Take a look at how fgets() works. You have 16 characters to read in + the newline + the null terminating character for a grand total of 16 + 1 + 1 = 18. Just because you don't see the characters doesn't mean they aren't there. fgets will automatically reserve space for applying the null terminating character '\0' so right of the bat you will only read num-1 characters. fgets also views the newline character '\n' as valid input so it will try to read that into the buffer as well.