2004-11-03 13:51:07 +00:00
|
|
|
|
.\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
|
|
|
|
|
.\"
|
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
|
.\" preserved on all copies.
|
|
|
|
|
.\"
|
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
|
.\" permission notice identical to this one.
|
|
|
|
|
.\"
|
|
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
|
.\" professionally.
|
|
|
|
|
.\"
|
|
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
|
.\"
|
|
|
|
|
.\" Rewritten old page, 960210, aeb@cwi.nl
|
|
|
|
|
.\" Updated, added strtok_r. 2000-02-13 Nicol<6F>s Lichtmaier <nick@debian.org>
|
|
|
|
|
.TH STRTOK 3 2000-02-13 "GNU" "Linux Programmer's Manual"
|
|
|
|
|
.SH NAME
|
|
|
|
|
strtok, strtok_r \- extract tokens from strings
|
|
|
|
|
.SH SYNOPSIS
|
|
|
|
|
.nf
|
|
|
|
|
.B #include <string.h>
|
|
|
|
|
.sp
|
|
|
|
|
.BI "char *strtok(char *" s ", const char *" delim );
|
|
|
|
|
.sp
|
|
|
|
|
.BI "char *strtok_r(char *" s ", const char *" delim ", char **" ptrptr );
|
|
|
|
|
.fi
|
|
|
|
|
.SH DESCRIPTION
|
|
|
|
|
A `token' is a nonempty string of characters not occurring in
|
|
|
|
|
the string \fIdelim\fP, followed by \e0 or by a character occurring
|
|
|
|
|
in \fIdelim\fP.
|
|
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
|
The \fBstrtok\fP() function can be used to parse the string \fIs\fP
|
|
|
|
|
into tokens. The first call to \fBstrtok\fP() should have \fIs\fP
|
2004-11-03 13:51:07 +00:00
|
|
|
|
as its first argument. Subsequent calls should have the first argument
|
|
|
|
|
set to NULL. Each call returns a pointer to the next token, or NULL
|
|
|
|
|
when no more tokens are found.
|
|
|
|
|
.PP
|
|
|
|
|
If a token ends with a delimiter, this delimiting character is
|
|
|
|
|
overwritten with a \e0 and a pointer to the next character is
|
2005-10-19 07:07:02 +00:00
|
|
|
|
saved for the next call to \fBstrtok\fP().
|
2004-11-03 13:51:07 +00:00
|
|
|
|
The delimiter string \fIdelim\fP may be different for each call.
|
|
|
|
|
.PP
|
|
|
|
|
The
|
2005-10-19 07:07:02 +00:00
|
|
|
|
.BR strtok_r ()
|
2004-11-03 13:51:07 +00:00
|
|
|
|
function is a reentrant version of the
|
2005-10-19 07:07:02 +00:00
|
|
|
|
.BR strtok ()
|
2004-11-03 13:51:07 +00:00
|
|
|
|
function, which instead of using its own static buffer, requires a pointer
|
|
|
|
|
to a user allocated char*. This pointer, the
|
|
|
|
|
.I ptrptr
|
|
|
|
|
parameter, must be the same while parsing the same string.
|
|
|
|
|
.\" .SH EXAMPLE
|
|
|
|
|
.\" The following parses words out of a string, using 'white space'
|
|
|
|
|
.\" separators, with
|
|
|
|
|
.\" .BR strtok_r() :
|
|
|
|
|
.\" .PP
|
|
|
|
|
.\" .nf
|
|
|
|
|
.\" char buf[128];
|
|
|
|
|
.\" char *sep = " \\t\\n";
|
|
|
|
|
.\" char *tok, *cb;
|
|
|
|
|
.\"
|
|
|
|
|
.\" snprintf(buf, sizeof(buf), "%s", " One Two\\tThree\\nFour\\n\\n");
|
|
|
|
|
.\"
|
|
|
|
|
.\" for ( tok = strtok_r(buf, sep, &cb); tok;
|
|
|
|
|
.\" tok = strtok_r(NULL, sep, &cb) )
|
|
|
|
|
.\" printf("%s\\n", tok);
|
|
|
|
|
.\" .fi
|
|
|
|
|
.SH BUGS
|
|
|
|
|
Never use these functions. If you do, note that:
|
|
|
|
|
.PP
|
|
|
|
|
.RS
|
|
|
|
|
These functions modify their first argument.
|
|
|
|
|
.PP
|
|
|
|
|
These functions cannot be used on constant strings.
|
|
|
|
|
.PP
|
|
|
|
|
The identity of the delimiting character is lost.
|
|
|
|
|
.PP
|
|
|
|
|
The
|
|
|
|
|
.BR strtok ()
|
|
|
|
|
function uses a static buffer while parsing, so it's not thread safe. Use
|
|
|
|
|
.BR strtok_r ()
|
|
|
|
|
if this matters to you.
|
|
|
|
|
.RE
|
|
|
|
|
.SH "RETURN VALUE"
|
2005-10-19 07:07:02 +00:00
|
|
|
|
The \fBstrtok\fP() function returns a pointer to the next token, or
|
2004-11-03 13:51:07 +00:00
|
|
|
|
NULL if there are no more tokens.
|
|
|
|
|
.SH "CONFORMING TO"
|
|
|
|
|
.TP
|
2005-10-19 14:16:57 +00:00
|
|
|
|
.BR strtok ()
|
2005-07-18 15:05:56 +00:00
|
|
|
|
SVID 3, POSIX, 4.3BSD, ISO 9899
|
2004-11-03 13:51:07 +00:00
|
|
|
|
.TP
|
2005-10-19 14:16:57 +00:00
|
|
|
|
.BR strtok_r ()
|
2004-11-03 13:51:07 +00:00
|
|
|
|
POSIX.1c
|
|
|
|
|
.SH "SEE ALSO"
|
|
|
|
|
.BR index (3),
|
|
|
|
|
.BR memchr (3),
|
|
|
|
|
.BR rindex (3),
|
|
|
|
|
.BR strchr (3),
|
|
|
|
|
.BR strpbrk (3),
|
|
|
|
|
.BR strsep (3),
|
|
|
|
|
.BR strspn (3),
|
|
|
|
|
.BR strstr (3)
|