当我尝试使用fgets( line,MAX,stdin)
读取字符串时,无法使用箭头向后移动并进行更正;会插入诸如^ [[D]之类的字符。是否有fgets
的有效替代方法。
这是我用来读取输入的周期:
char *buf = line;
char line[MAX];
printf("Enter x to quit\n>>");
for(;;) {
if(fgets(buf = line,stdin) == NULL || *buf == 'x')
break;
}
当*buf = '^[[D '
可以将光标向左移动,就像退格键一样,但是不会擦除以前的字符吗?
我想要的解决方案不是依靠bash readline
这样的外部库,而是纯粹的C ANSI。