1 .\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" Rewritten old page, 960210, aeb@cwi.nl
24 .\" Updated, added strtok_r. 2000-02-13 Nicolás Lichtmaier <nick@debian.org>
25 .TH STRTOK 3 2000-02-13 "GNU" "Linux Programmer's Manual"
27 strtok, strtok_r \- extract tokens from strings
30 .B #include <string.h>
32 .BI "char *strtok(char *" s ", const char *" delim );
34 .BI "char *strtok_r(char *" s ", const char *" delim ", char **" ptrptr );
37 A `token' is a nonempty string of characters not occurring in
38 the string \fIdelim\fP, followed by \e0 or by a character occurring
41 The \fBstrtok\fP() function can be used to parse the string \fIs\fP
42 into tokens. The first call to \fBstrtok\fP() should have \fIs\fP
43 as its first argument. Subsequent calls should have the first argument
44 set to NULL. Each call returns a pointer to the next token, or NULL
45 when no more tokens are found.
47 If a token ends with a delimiter, this delimiting character is
48 overwritten with a \e0 and a pointer to the next character is
49 saved for the next call to \fBstrtok\fP().
50 The delimiter string \fIdelim\fP may be different for each call.
54 function is a reentrant version of the
56 function, which instead of using its own static buffer, requires a pointer
57 to a user allocated char*. This pointer, the
59 parameter, must be the same while parsing the same string.
61 .\" The following parses words out of a string, using 'white space'
67 .\" char *sep = " \\t\\n";
70 .\" snprintf(buf, sizeof(buf), "%s", " One Two\\tThree\\nFour\\n\\n");
72 .\" for ( tok = strtok_r(buf, sep, &cb); tok;
73 .\" tok = strtok_r(NULL, sep, &cb) )
74 .\" printf("%s\\n", tok);
77 Never use these functions. If you do, note that:
80 These functions modify their first argument.
82 These functions cannot be used on constant strings.
84 The identity of the delimiting character is lost.
88 function uses a static buffer while parsing, so it's not thread safe. Use
90 if this matters to you.
93 The \fBstrtok\fP() function returns a pointer to the next token, or
94 NULL if there are no more tokens.
98 SVID 3, POSIX, 4.3BSD, ISO 9899