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