2

出于某种原因, ncurses不喜欢stdin,我知道我可以改用 getstr(),这就是我目前正在做的事情,

while (fgets(str, BUF, stdin) != NULL) {
    printf("input something ");
}

我怎样才能得到这个循环的标准输入的替代品(也许使用 getstr())?

任何帮助将不胜感激。

谢谢

4

2 回答 2

1

您可以使用 getstr() 从标准输入读取到缓冲区。查看 curses HOWTO以获取示例。

#include <ncurses.h>
#include <string.h> 

int main() {
   char buf[80];

   initscr();   

   do {
      getstr(buf);
      mvprintw(5, 0, "You entered: %s", buf);
   } while (strcmp(buf, "STOP"));

   endwin();

   return 0;
}
于 2009-11-20T21:59:37.973 回答
1

对于使用 ncurses 捕获输入,我会根据您的需要使用以下 3 个函数之一:

getch() 用于字符,scanw() 用于格式化输入,最后是 getstr()

于 2010-07-16T14:47:46.157 回答