I came across this problem when I want to check what I input is number. The scanf function will return 1 if I successfully input a number. So here is what I wro
scanf
Call scanf("%*[^\n]\n") inside the loop. This should be enough to discard anything associated with the cache.
scanf("%*[^\n]\n")