scanf("%d", &n);
reads an integer from standard input. Anything following that integer, particularly the new line that you entered when you typed Enter after the 4
, is left waiting to be read by the next input routine, in this case the first gets()
.
You got a blank line because that's what you gave it after the 4
.
That's the immediate cause of the problem you asked about, but you've got bigger problems.
Never use the gets
function. It does not guard against input that's longer than the array you're reading into, and it cannot be used safely. That's why it's been removed from the language as of the 2011 ISO C standard.
You can use fgets
to read a line of input, and then sscanf
to extract the integer from the line in memory. fgets
, unlike gets
, leaves the '\n'
in your array, so you'll have to deal with that (though you can ignore it when reading n
). Read the documentation for both functions, and pay attention to the values they return. (They have some problems of their own, but you don't need to worry about that for now.)