.\" 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ás Lichtmaier .TH STRTOK 3 "February 13, 2000" "GNU" "Linux Programmer's Manual" .SH NAME strtok, strtok_r \- extract tokens from strings .SH SYNOPSIS .nf .B #include .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 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 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 saved for the next call to \fBstrtok()\fP. The delimiter string \fIdelim\fP may be different for each call. .PP The .B strtok_r() function works the same as the .B strtok() function, but instead of using a static buffer it uses a pointer to a user allocated char* pointer. This pointer, the .I ptrptr parameter, must be the same while parsing the same string. .SH "BUGS" Never use these functions. If you do, note that: .PP .RS These functions modify their first argument. .PP The identity of the delimiting character is lost. .PP These functions cannot be used on constant strings. .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" The \fBstrtok()\fP function returns a pointer to the next token, or NULL if there are no more tokens. .SH "CONFORMING TO" .TP strtok() SVID 3, POSIX, BSD 4.3, ISO 9899 .TP strtok_r() POSIX.1c .SH "SEE ALSO" .BR index "(3), " memchr "(3), " rindex "(3), " strchr (3), .BR strpbrk "(3), " strsep "(3), " strspn "(3), " strstr (3)