Quote Originally Posted by koplersky View Post
Isn't the extra character a 1 and not a 4?

The problem is that you are not checking the return value of fgets(). From the linked page:



You probably have a newline at the end of your input.
fgets() reads the first line and later tries to read the second - which is empty - and returns NULL. Because it doesn't modify your string in this case, line still has the old contents (which is something like ['1', '\0', '2', '\0', ...], because of the operations done by strtok()). So the next call to strtok() reads the 1 from line and stops at the NULL character, but this gets printed to the screen as it's a valid number.
Thank you, this fixed the problem. It's been a long winter break and I'm a bit rusty.