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
the strtok issue is, per the man page, that strtok returns only “non empty” tokens with your given delimiters.
Given only one delimiter, the strchr approach is likely what I'd use. understanding strchr (and the similar strstr) is a pretty useful thing to have anyway, so it’s a good time to learn it. strchr makes no modifications and isn’t aiming to make tokens for you. It is looking for the first instance of a given byte in a C string and, provided it found it, returning you a pointer to that byte. as such, if it returns you something other than NULL, you’ve got a pointer to a byte. assuming you’re fine with the function modifying the buffer, you can convert that byte to a nul byte (\0), then print buffer, then a new line. You then advance your buffer pointer to the byte past the now-nul byte. Continue until strchr returns NULL, which is your last line - assuming the buffer is nul-terminated
Edit: example, now that I've got a real keyboard:
I see , thank you for the example, I think I've come up with a way I can use
strchrfor my purposes.Also, I've heard of there being man pages for C library functions before, is there a way I can run the man command with a C library function from the linux terminal?