Someone told me to use this code to clear the input buffer..
while((ch=getchar())!='\n' && ch !=EOF);
But I fail to understand how it actually works.
For example, there are two newline characters in the buffer
This is my buffer
Now getchar() grabs the first '\n', stores it in ch and compares ch with '\n' and EOF to see if the condition is true or not. Like this
(ch != '\n' && ch !=EOF) This gives (false && true) = false.
So the condition is false, the loop will terminate. What about the second '\n'? Its still in the buffer !!! So is this code for clearing only 1 newline character from the buffer?:idea: