The following works if fgets()
is being "skipped" after using scanf()
After saying:
scanf("%d", &loops);
Say:
char garbage[100];
fgets(garbage,100,stdin);
This will store anything left on the input buffer into the garbage variable.
This will effectively clear the input buffer and allow you to use fgets()
afterwards.
EDIT:
I have recently learned that there is an easier solution than the one above.
If you say getchar() after scanf(), it will allow you to use fgets() without issues. getchar() will get the next character in the input buffer, which in this case will be '\n'. Once you remove '\n' from the input buffer, fgets should work just fine.