Commit | Line | Data |
---|---|---|
3da2bc7c KB |
1 | .\" Copyright (c) 1990 The Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
4 | .\" This code is derived from software contributed to Berkeley by | |
5 | .\" Chris Torek. | |
6 | .\" | |
7 | .\" %sccs.include.redist.man% | |
8 | .\" | |
9 | .\" @(#)strsep.3 5.1 (Berkeley) %G% | |
10 | .\" | |
11 | .TH STRSEP 3 "" | |
12 | .UC 7 | |
13 | .SH NAME | |
14 | strsep \- separate strings | |
15 | .SH SYNOPSIS | |
16 | .nf | |
17 | .ft B | |
18 | #include <string.h> | |
19 | ||
20 | char * | |
21 | strsep(char **stringp, char *delim); | |
22 | .ft R | |
23 | .fi | |
24 | .SH DESCRIPTION | |
25 | .B Strsep | |
26 | locates in the null-terminated string at | |
27 | .I *stringp | |
28 | the first occurence of any character in | |
29 | .I delim | |
30 | and replaces this with a '\e0', | |
31 | records the location of the immediate following character in | |
32 | .IR *stringp , | |
33 | then returns the original value of | |
34 | .IR *stringp . | |
35 | If no delimiter characters are found, | |
36 | .B strsep | |
37 | sets | |
38 | .I *stringp | |
39 | to NULL; | |
40 | if | |
41 | .I *stringp | |
42 | is initially NULL, | |
43 | .B strsep | |
44 | returns NULL. | |
45 | .SH EXAMPLES | |
46 | The following uses | |
47 | .I strsep | |
48 | to parse strings containing runs of white space, | |
49 | making up an argument vector: | |
50 | .sp | |
51 | .nf | |
52 | .RS | |
53 | char inputstring[100]; | |
54 | char **argv[51], **ap = argv, *p, *val; | |
55 | .I "/* set up inputstring */" | |
56 | for (p = inputstring; p != NULL; ) { | |
57 | while ((val = strsep(&p, " \et")) != NULL && *val == '\e0'); | |
58 | *ap++ = val; | |
59 | } | |
60 | *ap = 0; | |
61 | .RE |