Every call to scanf picks up from where the last one stopped matching the input. This means that if an error occurred with the previous scanf, the input it failed to match is still left unread, as if the user typed ahead. If care isn't taken to discard error input, and a loop is used to read the input, your program can get caught in an infinite loop.
(Source: http://wpollock.com/CPlus/PrintfRef.htm)
You can also use flushall(); within the loop and before calling the scanf to tackle this problem.
(Source: http://wpollock.com/CPlus/PrintfRef.htm)
You can also use flushall(); within the loop and before calling the scanf to tackle this problem.
No comments:
Post a Comment