How it Works19 mins ago
C++ code issue
2 Answers
int keyI = 0;
while (keyI == 0)
{
keyI = getc(stdin);
}
For some reason this just returns 10 without running the loop to let me press anything. Does anyone have a solution?
while (keyI == 0)
{
keyI = getc(stdin);
}
For some reason this just returns 10 without running the loop to let me press anything. Does anyone have a solution?
Answers
That suggests that 10 (0x0a, or Line Feed) is sitting in your input buffer, probably from a previous operation - you've probably stopped at 13 (0x0d, or Carriage Return) previously, when you should have stopped at line feed. The best solution would be to clear it out of the input buffer at the correct time, on the previous operation. Alternativel y you could...
23:49 Sun 12th Jun 2011
That suggests that 10 (0x0a, or Line Feed) is sitting in your input buffer, probably from a previous operation - you've probably stopped at 13 (0x0d, or Carriage Return) previously, when you should have stopped at line feed. The best solution would be to clear it out of the input buffer at the correct time, on the previous operation. Alternatively you could flush the input buffer before executing the above code.