Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C, strtok

Name: Anonymous 2010-02-16 13:01

Hello /prog/

Could anyone help me with using the C function strtok and strtok_r?

I've read the man pages and it doesn't provide much help. Try compiling this code example gotten from the man pages:

http://pastebin.com/d11d44ccf

Name: Anonymous 2010-02-16 13:21

IIRC

strtok(STRING, TOKENS);
returns a pointer to first substring in STRING up to a character in TOKENS
strtok(NULL, TOKENS)
returns a pointer to the next substring that contains no characters from TOKENS, keeps the old string internally

if a call to strtok returns NULL then there is no more substrings that contain no characters in TOKENS

strtok modifies the original string by adding \0s so make a copy if you need to keep it.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List