File: strtok.3

package info (click to toggle)
manpages-ja 0.5.0.0.20100315-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 21,156 kB
  • ctags: 1
  • sloc: sh: 13,935; perl: 157; makefile: 114
file content (208 lines) | stat: -rw-r--r-- 5,804 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
.\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
.\" and Copyright (C) 2005 Michael Kerrisk (mtk.manpages@gmail.com)
.\"
.\" 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 Nicolas Lichtmaier <nick@debian.org>
.\" 2005-11-17, mtk: Substantial parts rewritten
.\"
.\" Japanese Version Copyright (c) 1998 Ishii Tatsuo all rights reserved.
.\" Translated 1998-03-27, Ishii Tatsuo <rfun@azusa.shinshu-u.ac.jp>
.\" Updated 2000-04-05, Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2000-09-21, Kentaro Shirakata
.\" Updated 2002-03-28, Kentaro Shirakata
.\" Updated 2005-11-19, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
.\"
.TH STRTOK 3  2008-10-29 "GNU" "Linux Programmer's Manual"
.SH ̾
strtok, strtok_r \- ʸ󤫤ȡФ
.SH 
.nf
.B #include <string.h>
.sp
.BI "char *strtok(char *" str ", const char *" delim );
.sp
.BI "char *strtok_r(char *" str ", const char *" delim ", char **" saveptr );
.fi
.sp
.in -4n
glibc εǽޥ׷
.RB ( feature_test_macros (7)
):
.in
.sp
.ad l
.BR strtok_r ():
_SVID_SOURCE || _BSD_SOURCE || _POSIX_C_SOURCE\ >=\ 1 ||
_XOPEN_SOURCE || _POSIX_SOURCE
.ad b
.SH 
.BR strtok ()
ؿʸϤƥȡʬ䤹롣
.BR strtok ()
ǽ˸ƤӽФݤˤϡоݤʸ \fIstr\fP 
ꤹ롣ƱʸβϤԤθθƤӽФǤϡ
\fIstr\fP ˤ NULL ꤹ롣

\fIdelim\fP ˤϡϤʸȡ˶ڤʸ
ꤹ롣ƱʸϤϢθƤӽФˤơ
\fIdelim\fP ˰㤦ʸꤷƤ褤

.BR strtok ()
Τ줾θƤӽФǤϡΥȡ
Ǽ NULL ü줿ʸؤΥݥ󥿤֤롣
ʸˤ϶ڤʸϴޤޤʤ
ʾȡ󤬸ĤʤäˤϡNULL ֤롣

оݤʸ2İʾζڤʸϢ³Ƥˤϡ
ĤζڤʸȤߤʤ롣
ʸƬˤڤʸ̵뤵롣ȡ
.BR strtok ()
֤ȡϾ˶ǤʤʸȤʤ롣

.BR strtok_r ()
ؿ
.BR strtok ()
ΥꥨȥǤǤ롣
\fIsaveptr\fP  \fIchar *\fP ѿؤΥݥ󥿤Ǥꡢ
ƱʸβϤԤ
.BR strtok_r ()
θƤӽФ֤ǽ¸뤿
.BR strtok_r ()
ǻѤ롣

.BR strtok_r ()
ǽ˸ƤӽФݤˤϡ
.I str
ϲоݤʸؤƤʤФʤ餺
.I saveptr
̵ͤ뤵롣ʹߤθƤӽФǤϡ
.I str
 NULL Ȥ
.I saveptr
θƤӽФʹѹʤ褦ˤʤФʤʤ

.BR strtok_r ()
θƤӽФ˰ۤʤ \fIsaveptr\fP ꤹ뤳Ȥǡ
ۤʤʸβϤƱ˹ԤȤǤ롣
.SH ֤
.BR strtok ()

.BR strtok_r ()
ϼΥȡؤΥݥ󥿤
ȡ󤬤ʤ NULL ֤
.SH 
.TP
.BR strtok ()
SVr4, POSIX.1-2001, 4.3BSD, C89, C99.
.TP
.BR strtok_r ()
POSIX.1-2001.
.SH Х
δؿȤΤϿŤ˶̣뤳ȡ
ѤϡʲդɬפǤ롣
.IP * 2
δؿϤκǽΰѹ롣
.IP *
δؿ const ʸǤϻȤʤ
.IP *
ڤʸΤϼƤޤ
.IP *
.BR strtok ()
ؿʸβϤŪХåեѤΤǡåɥդǤʤ
줬ˤʤ
.BR strtok_r ()
Ѥ뤳ȡ
.SH 
ʲΥץϡ
.BR strtok_r ()
Ѥ롼פҤˤƻѤ
ʸ2ؤΥȡʬ䤹ΤǤ롣
1ܤΥޥɥ饤ˤϡоݤʸꤹ롣
2ܤΰˤϡʸ礭ʡץȡʬ䤹뤿
Ѥڤʸꤹ롣
3ܤΰˤϡ礭ʡץȡ٤ʬ䤹뤿
Ѥڤʸꤹ롣
.PP
.PP
Υץνʲ˼
.PP
.in +4n
.nf
.RB "$" " ./a.out \(aqa/bbb///cc;xxx:yyy:\(aq \(aq:;\(aq \(aq/\(aq"
1: a/bbb///cc
         \-\-> a
         \-\-> bbb
         \-\-> cc
2: xxx
         \-\-> xxx
3: yyy
         \-\-> yyy
.fi
.in
.SS ץΥ
\&
.nf
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
main(int argc, char *argv[])
{
    char *str1, *str2, *token, *subtoken;
    char *saveptr1, *saveptr2;
    int j;

    if (argc != 4) {
        fprintf(stderr, "Usage: %s string delim subdelim\\n",
                argv[0]);
        exit(EXIT_FAILURE);
    }

    for (j = 1, str1 = argv[1]; ; j++, str1 = NULL) {
        token = strtok_r(str1, argv[2], &saveptr1);
        if (token == NULL)
            break;
        printf("%d: %s\\n", j, token);

        for (str2 = token; ; str2 = NULL) {
            subtoken = strtok_r(str2, argv[3], &saveptr2);
            if (subtoken == NULL)
                break;
            printf("\t \-\-> %s\\n", subtoken);
        }
    }

    exit(EXIT_SUCCESS);
} /* main */
.fi
.SH Ϣ
.BR index (3),
.BR memchr (3),
.BR rindex (3),
.BR strchr (3),
.BR strpbrk (3),
.BR strsep (3),
.BR strspn (3),
.BR strstr (3),
.BR wcstok (3)