]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/strtok.3
Automated unformatting of parentheses using unformat_parens.sh
[thirdparty/man-pages.git] / man3 / strtok.3
1 .\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
2 .\"
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.
6 .\"
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.
11 .\"
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
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
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"
26 .SH NAME
27 strtok, strtok_r \- extract tokens from strings
28 .SH SYNOPSIS
29 .nf
30 .B #include <string.h>
31 .sp
32 .BI "char *strtok(char *" s ", const char *" delim );
33 .sp
34 .BI "char *strtok_r(char *" s ", const char *" delim ", char **" ptrptr );
35 .fi
36 .SH DESCRIPTION
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
39 in \fIdelim\fP.
40 .PP
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.
46 .PP
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.
51 .PP
52 The
53 .BR strtok_r ()
54 function is a reentrant version of the
55 .BR strtok ()
56 function, which instead of using its own static buffer, requires a pointer
57 to a user allocated char*. This pointer, the
58 .I ptrptr
59 parameter, must be the same while parsing the same string.
60 .\" .SH EXAMPLE
61 .\" The following parses words out of a string, using 'white space'
62 .\" separators, with
63 .\" .BR strtok_r() :
64 .\" .PP
65 .\" .nf
66 .\" char buf[128];
67 .\" char *sep = " \\t\\n";
68 .\" char *tok, *cb;
69 .\"
70 .\" snprintf(buf, sizeof(buf), "%s", " One Two\\tThree\\nFour\\n\\n");
71 .\"
72 .\" for ( tok = strtok_r(buf, sep, &cb); tok;
73 .\" tok = strtok_r(NULL, sep, &cb) )
74 .\" printf("%s\\n", tok);
75 .\" .fi
76 .SH BUGS
77 Never use these functions. If you do, note that:
78 .PP
79 .RS
80 These functions modify their first argument.
81 .PP
82 These functions cannot be used on constant strings.
83 .PP
84 The identity of the delimiting character is lost.
85 .PP
86 The
87 .BR strtok ()
88 function uses a static buffer while parsing, so it's not thread safe. Use
89 .BR strtok_r ()
90 if this matters to you.
91 .RE
92 .SH "RETURN VALUE"
93 The \fBstrtok\fP() function returns a pointer to the next token, or
94 NULL if there are no more tokens.
95 .SH "CONFORMING TO"
96 .TP
97 strtok()
98 SVID 3, POSIX, 4.3BSD, ISO 9899
99 .TP
100 strtok_r()
101 POSIX.1c
102 .SH "SEE ALSO"
103 .BR index (3),
104 .BR memchr (3),
105 .BR rindex (3),
106 .BR strchr (3),
107 .BR strpbrk (3),
108 .BR strsep (3),
109 .BR strspn (3),
110 .BR strstr (3)