Use strtok()
. From the man page for it:
The strtok() function parses a string into a sequence of tokens. On the first call to strtok() the string to be parsed should be specified in str. In each subsequent call that should parse the same string, str should be NULL.
Each call to strtok() returns a pointer to a null-terminated string containing the next token. This string does not include the delimiting byte. If no more tokens are found, strtok() returns NULL.
In other words, loop through your string and keep calling strtok()
until it returns NULL
in order to get all the words (that would be split on the delimiters specified to the first call of strtok()
) returned as char*
.