scanf
не потребляет новую линию и, следовательно, является естественным врагом fgets
. Не складывайте их без хорошего взлома. Оба этих параметра будут работать:
// Option 1 - eat the newline
scanf("%d", &a);
getchar(); // reads the newline character
// Option 2 - use fgets, then scan what was read
char tmp[50];
fgets(tmp, 50, stdin);
sscanf(tmp, "%d", &a);
// note that you might have read too many characters at this point and
// must interprete them, too