summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraaron <>1999-07-03 15:58:50 +0000
committeraaron <>1999-07-03 15:58:50 +0000
commitea23c585195e4a1bed519c1bd535733bcfe47bb1 (patch)
tree631d49e1b6ca4547f06fbd0211cc5a78af9a62de
parent8813c538a1d0dc6b2173d32778f20b1b27b4164a (diff)
downloadopenbsd-ea23c585195e4a1bed519c1bd535733bcfe47bb1.tar.gz
openbsd-ea23c585195e4a1bed519c1bd535733bcfe47bb1.tar.bz2
openbsd-ea23c585195e4a1bed519c1bd535733bcfe47bb1.zip
add an example
-rw-r--r--src/lib/libc/string/strtok.341
1 files changed, 38 insertions, 3 deletions
diff --git a/src/lib/libc/string/strtok.3 b/src/lib/libc/string/strtok.3
index c8463200bf..d43046ae5c 100644
--- a/src/lib/libc/string/strtok.3
+++ b/src/lib/libc/string/strtok.3
@@ -33,7 +33,7 @@
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE. 34.\" SUCH DAMAGE.
35.\" 35.\"
36.\" $OpenBSD: strtok.3,v 1.6 1999/06/29 18:01:34 aaron Exp $ 36.\" $OpenBSD: strtok.3,v 1.7 1999/07/03 15:58:50 aaron Exp $
37.\" 37.\"
38.Dd June 29, 1991 38.Dd June 29, 1991
39.Dt STRTOK 3 39.Dt STRTOK 3
@@ -73,10 +73,44 @@ The
73.Fn strtok 73.Fn strtok
74function 74function
75returns a pointer to the beginning of each subsequent token in the string, 75returns a pointer to the beginning of each subsequent token in the string,
76after replacing the separator character itself with a 76after replacing the separator character itself with an
77.Dv NUL 77.Tn ASCII NUL
78character. 78character.
79When no more tokens remain, a null pointer is returned. 79When no more tokens remain, a null pointer is returned.
80.Pp
81Since
82.Fn strtok
83modifies the string,
84.Fa str
85should not point to an area in the initialized data segment.
86.Pp
87.Sh EXAMPLES
88The following will construct an array of pointers to each individual word in
89the string
90.Va s :
91.Bd -literal -offset indent
92#define MAXTOKENS 128
93
94char s[512], *p, *tokens[MAXTOKENS];
95int i = 0;
96
97snprintf(s, sizeof(s), "cat dog horse cow");
98
99for ((p = strtok(s, " ")); p; (p = strtok(NULL, " ")), i++) {
100 if (i < MAXTOKENS)
101 tokens[i] = p;
102}
103tokens[i] = '\e0';
104.Ed
105.Pp
106That is, tokens[0] will point to
107.Qq cat ,
108tokens[1] will point to
109.Qq dog ,
110tokens[2] will point to
111.Qq horse ,
112and tokens[3] will point to
113.Qq cow .
80.Sh SEE ALSO 114.Sh SEE ALSO
81.Xr index 3 , 115.Xr index 3 ,
82.Xr memchr 3 , 116.Xr memchr 3 ,
@@ -107,3 +141,4 @@ may return a non-null value.
107Since this implementation always alters the next starting point, 141Since this implementation always alters the next starting point,
108such a sequence of calls would always return 142such a sequence of calls would always return
109.Dv NULL . 143.Dv NULL .
144