this post was submitted on 17 Aug 2026
4 points (100.0% liked)
C Programming Language
1336 readers
1 users here now
Welcome to the C community!
C is quirky, flawed, and an enormous success.
... When I read commentary about suggestions for where C should go, I often think back and give thanks that it wasn't developed under the advice of a worldwide crowd.
... The only way to learn a new programming language is by writing programs in it.
- irc: #c
๐ https://en.cppreference.com/w/c
founded 3 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Any chance you are running this on an OS with a "new line" character that isn't "\n"? Windows for example could be "\r\n". I tried on Linux and it worked, although I only grabbed the necessary parts, so if something else is breaking, I can't say. Or perhaps I misunderstood the issue altogether. Here is what I see:
The function:
And the output:
It feels like your file may have been CRLF instead of just LF. strtok would eat an empty line if it was strictly delimited by the given delimiter. Removing empty tokens is part of its intentional behavior.
I am on Linux as well, it does work but it skips empty lines which will make the line numbers inaccurate.