C program Getchar mistake
Published in
2 min readSep 2, 2020
Today I am helping my tutor-student debug his program which is a 2048 game.
Here is program
And I get the result
The result show two loops , char and ‘Enter’ as an input.Getchar or scanf where the input type is char , there is some problem here. The reason is it also take line Feed(LF) when you press enter . The line Feed(LF) still in the input buffer .
Method
We can clean the input buffer
I add input=getchar(); in line47
here getchar get the line Feed