C 语言中的 NCURSES 标准输入

发布于 2024-08-12 10:52:22 字数 276 浏览 4 评论 0原文

由于某种原因 ncurses 不喜欢 stdin,我知道我可以使用 getstr() 代替,这就是我到目前为止所做的,

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

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

任何帮助将不胜感激。

谢谢

For some reason ncurses does not like stdin, I know I could use instead getstr(), here it is what I'm doing so far,

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

How could I get an alternative to stdin for this loop (perhaps using getstr())?

Any help will be appreciate it.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独夜无伴 2024-08-19 10:52:22

为了使用 ncurses 捕获输入,我将根据您的需要使用 3 个函数之一:

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

For capturing input using ncurses, I would use one of the 3 functions based upon your needs:

getch() for characters, scanw() for formatted input and finally getstr()

奈何桥上唱咆哮 2024-08-19 10:52:22

您可以使用 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;
}

You can use getstr() to read from stdin to a buffer. Check the curses HOWTO for examples.

#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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文