C programming question about input...

Started by
2 comments, last by KingRuss 22 years, 6 months ago
I call several getch()''s durring my program and I was wondering how to stop the user from doing stuff before they can see it. Someone on a different site said something about using fflush to empty the stdin, but didn''t say exactly how and what I tried didn''t work. If there is another way to do this then go ahead and suggest it. Thanks in advance... (in regular c only) "Practice means good, Perfect Practice means Perfect"
"Practice makes good, Perfect Practice makes Perfect"
Advertisement
I don''t fully understand your question, but nevertheless I suggest you look at getche(), which echoes the character to the console. Also look at getc() and putc() in combination. One of them may fit your situation perfectly.
IIRC kbhit() should do the trick. I believe something along the lines of the following functions might work.

     void flush_input_buffer(void){    // Read keys as long as there is still    // a keypress in the input buffer    while (kbhit())        getch();};  char get_new_char(void){    // remove all keypresses from the input buffer...    flush_input_buffer();    // ...and wait for a new keypress    return (char)getch();};      


Edited by - Dactylos on September 23, 2001 2:04:10 AM
Thanks Dactylos, that worked perfectly so far, and hopefully it will last. Now I can go on to the equipment screen... this might take a while, but soon my game will be complete!

"Practice means good, Perfect Practice means Perfect"
"Practice makes good, Perfect Practice makes Perfect"

This topic is closed to new replies.

Advertisement