when I try to read a string with fgets( line, MAX, stdin)
, I cannot use the arrows to move back and make correction; characters such as ^[[D are inserted instead. Is there a valid alternative to fgets
.
This is the cycle I use to read the input:
char *buf = line;
char line[MAX];
printf("Enter x to quit\n>>");
for(;;) {
if(fgets(buf = line, MAX, stdin) == NULL || *buf == 'x')
break;
}
When *buf = '^[[D '
is there a way to move the cursors left like the backspace but without erasing previous characters?
I'd like a solution that doesn't resort on external libraries such as bash readline
but purely C ANSI.