xref: /original-bsd/lib/libc/string/strtok.3 (revision f737e041)
1.\" Copyright (c) 1988, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the American National Standards Committee X3, on Information
6.\" Processing Systems.
7.\"
8.\" %sccs.include.redist.man%
9.\"
10.\"     @(#)strtok.3	8.2 (Berkeley) 02/03/94
11.\"
12.Dd
13.Dt STRTOK 3
14.Os BSD 3
15.Sh NAME
16.Nm strtok
17.Nd string tokens
18.Sh SYNOPSIS
19.Fd #include <string.h>
20.Ft char *
21.Fn strtok "char *str" "const char *sep"
22.Sh DESCRIPTION
23.Bf -symbolic
24This interface is obsoleted by strsep(3).
25.Ef
26.Pp
27The
28.Fn strtok
29function
30is used to isolate sequential tokens in a null-terminated string,
31.Fa str .
32These tokens are separated in the string by at least one of the
33characters in
34.Fa sep .
35The first time that
36.Fn strtok
37is called,
38.Fa str
39should be specified; subsequent calls, wishing to obtain further tokens
40from the same string, should pass a null pointer instead.
41The separator string,
42.Fa sep ,
43must be supplied each time, and may change between calls.
44.Pp
45The
46.Fn strtok
47function
48returns a pointer to the beginning of each subsequent token in the string,
49after replacing the token itself with a
50.Dv NUL
51character.
52When no more tokens remain, a null pointer is returned.
53.Sh SEE ALSO
54.Xr index 3 ,
55.Xr memchr 3 ,
56.Xr rindex 3 ,
57.Xr strchr 3 ,
58.Xr strcspn 3 ,
59.Xr strpbrk 3 ,
60.Xr strrchr 3 ,
61.Xr strsep 3 ,
62.Xr strspn 3 ,
63.Xr strstr 3
64.Sh STANDARDS
65The
66.Fn strtok
67function
68conforms to
69.St -ansiC .
70.Sh BUGS
71There is no way to get tokens from multiple strings simultaneously.
72.Pp
73The System V
74.Fn strtok ,
75if handed a string containing only delimiter characters,
76will not alter the next starting point, so that a call to
77.Fn strtok
78with a different (or empty) delimiter string
79may return a
80.Pf non- Dv NULL
81value.
82Since this implementation always alters the next starting point,
83such a sequence of calls would always return
84.Dv NULL .
85