Ignore carriage returns in scanf before data.... to keep layout of console based graphics with conio

Posted by volting on Stack Overflow See other posts from Stack Overflow or by volting
Published on 2010-03-15T20:42:15Z Indexed on 2010/03/15 20:49 UTC
Read the original article Hit count: 274

Filed under:
|
|
|
|

I have the misfortune of having use conio.h in vc++ 6 for a college assignment,

My problem is that my graphic setup is in the center of the screen...

e.g.

gotoxy( getcols()/2, getrows()/2);
printf("Enter something");
scanf( "%d", &something );  

now if someone accidentally hits enter before they enter the "something", then the cursor gets reset to the left of the screen on the next line.

Iv tried flushing the keyboard and bios buffers with fflush(stdin) and getchar(), which like I expected didn't work!

Any help/ideas would be appreciated, Thanks, V

© Stack Overflow or respective owner

Related posts about console-application

Related posts about console