开发者

making fgets not print stuff like ^G or ^D caused by arrow keys or other control keys

Basically the title is self explaining. I'm programming in C and i use fgets as the input function but i do not want that control character开发者_开发知识库s get printed.


fgets() is rather simple, and doesn't offer you much control over what appears on the screen. I don't think that it's possible to do this. You may want to look into something more powerful - like readline.


Yes, as other post says, readline is your best bet. Its simple too. If you are on Linux, it should already be installed. try the following:

#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>

// compile as:  gcc <file>.c -lreadline -lcurses 
int main (int argc, char *argv[])
{
    char *input = readline("Enter words: ");
    printf("\n Input: [%s]\n", input );
    return 0;
}

-- HTH.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜