Donate SIGN UP

C++ code issue

Avatar Image
TeztMethod | 00:34 Mon 13th Jun 2011 | Technology
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?
Gravatar

Answers

1 to 2 of 2rss feed

Avatar Image
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...
00:49 Mon 13th 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.
Question Author
Thanks XD

1 to 2 of 2rss feed

Do you know the answer?

C++ code issue

Answer Question >>