79276922

Date: 2024-12-13 00:11:24
Score: 1.5
Natty:
Report link

your post is confusing!, and as you've not posted a [https://stackoverflow.com/help/minimal-reproducible-example][1] , here's a trivial example of terminating on ^C for illustration only ...

NB:(readline already handles this by default !

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <readline/readline.h>

void trapC()
{
    puts("\n^c caught, terminating!");
    exit(1);
}

int main()
{
    char *buff;
    (void) signal(SIGINT,trapC);

    for(;;)
    {
        buff = readline( "\nenter stuff [^C to terminate] :");
        if ( buff )
                printf("you entered [%s]\n", buff );
        free(buff);
    }
    return(0);
}

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Blacklisted phrase (1): stackoverflow.com/help
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: ticktalk