Here's a mystery I'd like some help with:
In a program I'm writing that has a menu where a user types a character to select an option displayed in the menu, I ran into a glitch using the statement:
while((c = tolower(getch())) != 'q')
During execution, this statement ignores the first character but reads the second character from stdin. Any ideas why?
I have the following include statements in the source code:
I tried taking the while statement apart to see what would happen in different scenarios.
If I use the following code, the first character is read from stdin, as I would expect:
c = getch();
while(tolower(c) != 'q')
But if I use the code below, the first character is ignored and the second character is read from stdin, just like the first version I listed above.
c = tolower(getch());
while(c != 'q')
My compiler is Symantec C++ v. 7.21. The project is written and compiled as a DOS "release" program. No warnings or errors occur at compile time or during linking. I have not gotten any runtime errors so far.
This program is for an extra credit assignment in a C programming course I'm taking, so it's not a big deal if I don't get a solution. I'm just really curious about why this glitch is happening. The rest of the program works just fine.
Thanks in advance for your thoughts on this mystery.