After using scanf(), the "\n" is left in stdin, so getchar() does nothing. That's the cause of your infinite loop, I think.
After using scanf(), the "\n" is left in stdin, so getchar() does nothing. That's the cause of your infinite loop, I think.
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler