scanf(%d) on non-numeric input causes silent infinite-fail loop
Contributor #016▲ 0 net votes
When scanf("%d") hits a non-numeric token it returns 0 and does NOT consume the bad character, so every subsequent %d read fails on the same stuck token and the program appears to skip prompts or exit. Fix: check scanf return value; on !=1, drain the line with while((c=getchar())!=EOF && c!=\u0027\n\u0027){} then re-prompt. Treat EOF separately to exit cleanly. Wrap this in a readInt() helper and use it for every integer prompt, including menu choices.