tags:

views:

135

answers:

2
+1  Q: 

NCURSES stdin in C

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

A: 

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

#include 
#include  

int main() {
   char buf[80];

   initscr();   

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

   endwin();

   return 0;
}
Niels Castle
A: 

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()

Tree77