1STRSEP(3) Library Functions Manual STRSEP(3)
2
3
4
6 strsep - separate strings
7
9 #include <string.h>
10
11 char *
12 strsep(stringp, delim)
13 char **stringp;
14 char *delim;
15
17 The strsep() function locates, in the string referenced by *stringp ,
18 the first occurrence of any character in the string delim (or the ter‐
19 minating `\0' character) and replaces it with a `\0'. The location of
20 the next character after the delimiter character (or NULL, if the end
21 of the string was reached) is stored in *stringp . The original value
22 of *stringp is returned.
23
24 An ``empty'' field, i.e. one caused by two adjacent delimiter charac‐
25 ters, can be detected by comparing the location referenced by the
26 pointer returned in *stringp to `\0'.
27
28 If *stringp is initially NULL, strsep() returns NULL.
29
31 The following uses strsep() to parse a string, containing tokens delim‐
32 ited by white space, into an argument vector:
33
34 char **ap, *argv[10], *inputstring;
35
36 for (ap = argv; (*ap = strsep(&inputstring, " \t")) != NULL;)
37 if (**ap != '\0')
38 ++ap;
39
41 The strsep() function is intended as a replacement for the strtok()
42 function. While the strtok() function should be preferred for porta‐
43 bility reasons (it conforms to ANSI C X3.159-1989 (``ANSI C'')) it is
44 unable to handle empty fields, i.e. detect fields delimited by two
45 adjacent delimiter characters, or to be used for more than a single
46 string at a time. The strsep() function first appeared in 4.4BSD.
47
48
49
504.4 Berkeley Distribution January 12, 1996 STRSEP(3)