strsep -- extract token from string


#include <string.h>

char * strsep(char * * stringp, const char * delim);


The strsep() function shall find the first token in the string referenced by the pointer stringp, using the characters in delim as delimiters.

If stringp is NULL, strsep() shall return NULL and do nothing else.

If stringp is non-NULL, strsep() shall find the first token in the string referenced by stringp, where tokens are delimited by characters in the string delim. This token shall be terminated with a \0 character by overwriting the delimiter, and stringp shall be updated to point past the token. In case no delimiter was found, the token is taken to be the entire string referenced by stringp, and the location referenced by stringp is made NULL.

Return Value

strsep() shall return a pointer to the beginning of the token.


The strsep() function was introduced as a replacement for strtok(), since the latter cannot handle empty fields. However, strtok() conforms to ISO C (1999) and to ISO POSIX (2003) and hence is more portable.

See Also

strtok(), strtok_r().