Computing.Net > Forums > Programming > Clearing the keyboard buffer in C

Clearing the keyboard buffer in C

Reply to Message Icon

Original Message
Name: brds
Date: July 3, 2005 at 12:29:54 Pacific
Subject: Clearing the keyboard buffer in C
OS: windows xp
CPU/Ram: 512
Comment:

hello,
I was wondering how to clear the keyboard buffer. I compiled me exe file but it doesn't wait for the user to press a button before it exits. I know that the problem is solved when the keyboard buffer is cleared (I ran into this problem before) but i just dont remember how to clear it.

Thanks for the help,
brds


Report Offensive Message For Removal

Response Number 1
Name: borelli35
Date: July 3, 2005 at 19:44:54 Pacific
Subject: Clearing the keyboard buffer in C
Reply: (edit)

If you are using keypressed it will only tell you that the keyboard buffer has a character waiting. If you want to be certain that the keyboard buffer is cleared then place an until loop in the right part of your code that repeats until !keypressed (not keypressed) and do a readkey or what ever your character retrieval function for your compiler would be within that loop.

John W. Borelli
IT Specialist
Hawkeye Security
borelli35


Report Offensive Follow Up For Removal

Response Number 2
Name: dtech10
Date: July 4, 2005 at 07:26:12 Pacific
Subject: Clearing the keyboard buffer in C
Reply: (edit)

Hi Brds
Try ...
#include <stdio.h>
fflush(stdin);


Report Offensive Follow Up For Removal

Response Number 3
Name: borelli35
Date: July 4, 2005 at 16:59:14 Pacific
Subject: Clearing the keyboard buffer in C
Reply: (edit)

fflush would work but is more overhead expensive.

John W. Borelli
IT Specialist
Hawkeye Security

Link to my email address


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Clearing the keyboard buffer in C

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software