Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

KingRuss

C programming question about input...

This topic is 6171 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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"

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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"

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!