Input in C. Scanf before gets. Problem

Try:

scanf("%d\n", &a);

gets only reads the ‘\n’ that scanf leaves in. Also, you should use fgets not gets: http://www.cplusplus.com/reference/clibrary/cstdio/fgets/ to avoid possible buffer overflows.

Edit:

if the above doesn’t work, try:

...
scanf("%d", &a);
getc(stdin);
...

Leave a Comment