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
Just call scanf("%*[^\n]\n") inside the loop, and it will discard the "cache".
scanf("%*[^\n]\n")