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