How do i check to see if a key is being pressed while in a "while()" loop?
If you're in a Windows app - your window will receive a WM_CHAR message. For console apps, try the getch() function. Unfortunately I think that doesn't return until a key is pressed...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You". -- Linus Torvalds
Use the _getch function. Code: #include <conio.h> #include <ctype.h> void main() { char ch; _cputs( "Enter a letter: " ); // Loop until "Y" is pressed do { ch = _getch(); ch = toupper( ch ); } while( ch != 'Y'); }
#include <conio.h> #include <ctype.h> void main() { char ch; _cputs( "Enter a letter: " ); // Loop until "Y" is pressed do { ch = _getch(); ch = toupper( ch ); } while( ch != 'Y'); }
Forum Rules