how to flush the console buffer?

Posted by DoronS on Stack Overflow See other posts from Stack Overflow or by DoronS
Published on 2011-01-01T07:26:00Z Indexed on 2011/01/01 7:54 UTC
Read the original article Hit count: 304

Filed under:
|

Hi all,

i have some code that run repetedly :

printf("do you want to continue? Y/N: \n");
keepplaying = getchar();

in the next my code is running it doesnt wait for input. i found out that getchar in the seconed time use '\n' as the charcter. im gussing this is due to some buffer the sdio has, so it save the last input which was "Y\n" or "N\n".

my Q is, how do i flush the buffer before using the getchar, which will make getchar wait for my answer?

© Stack Overflow or respective owner

Related posts about c

    Related posts about getchar