I'm trying to write a simple program to read an integer and then a string, then print both to standard output. Ideally, the execution should look something like this:
Input the number.
> 10
Input the string.
> a string
number: 10
string: a string
However, when I run the program, it freezes after the call to scanf() until more input is provided.
Input the number.
> 10
a string
Input the string.
> 
number: 10
string: a string
Why is it waiting for input before fgets() is ever called?
 #include <stdio.h>
 
 int main()
 {
     int number;
     char string[32];
 
     printf("Input the number.\n> ");
     scanf("%d\n", &number);
 
     printf("\nInput the string.\n> ");
     fgets(string, 32, stdin);
 
     printf("\nnumber: %d\nstring: %s\n", number, string);
 }
 
     
    