[Previous] [Contents] [Next]

strsep()

Separate strings

Synopsis:

#include <string.h>

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

Library:

libc

Description:

The strsep() function locates in the null-terminated string pointed to by stringp the first occurrence of any character in delim and replaces this with a \0, records the location of the next character in *stringp, then returns the original value of *stringp. If no delimiter characters are found, strsep() sets *stringp to NULL; if *stringp is initially NULL, strsep() returns NULL.

Returns:

A pointer to the original value of *stringp.

Examples:

Parse strings containing runs of white space, making up an argument vector:

char inputstring[100];
char **argv[51], **ap = argv, *p, *val;

/* set up inputstring */
for (p = inputstring; p != NULL; ) {
    while ((val = strsep(&p, " \t")) != NULL && *val == '\0');
    *ap++ = val;
}
*ap = 0;

Classification:

Unix

Safety:
Cancellation point No
Interrupt handler Yes
Signal handler Yes
Thread Yes

See also:

strtok()


[Previous] [Contents] [Next]