1 .\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
2 .\" and Copyright (C) 2005 Michael Kerrisk (mtk.manpages@gmail.com)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" Rewritten old page, 960210, aeb@cwi.nl
25 .\" Updated, added strtok_r. 2000-02-13 Nicolas Lichtmaier <nick@debian.org>
26 .\" 2005-11-17, mtk: Substantial parts rewritten
28 .\" Japanese Version Copyright (c) 1998 Ishii Tatsuo all rights reserved.
29 .\" Translated 1998-03-27, Ishii Tatsuo <rfun@azusa.shinshu-u.ac.jp>
30 .\" Updated 2000-04-05, Kentaro Shirakata <argrath@ub32.org>
31 .\" Updated 2000-09-21, Kentaro Shirakata
32 .\" Updated 2002-03-28, Kentaro Shirakata
33 .\" Updated 2005-11-19, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
35 .TH STRTOK 3 2010-09-27 "GNU" "Linux Programmer's Manual"
37 strtok, strtok_r \- ʸ»úÎ󤫤é¥È¡¼¥¯¥ó¤ò¼è¤ê½Ð¤¹
40 .B #include <string.h>
42 .BI "char *strtok(char *" str ", const char *" delim );
44 .BI "char *strtok_r(char *" str ", const char *" delim ", char **" saveptr );
48 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
49 .RB ( feature_test_macros (7)
55 _SVID_SOURCE || _BSD_SOURCE || _POSIX_C_SOURCE\ >=\ 1 ||
56 _XOPEN_SOURCE || _POSIX_SOURCE
60 ´Ø¿ô¤Ïʸ»úÎó¤ò²òÀϤ·¤Æ¥È¡¼¥¯¥ó¤Ëʬ³ä¤¹¤ë¡£
62 ¤òºÇ½é¤Ë¸Æ¤Ó½Ð¤¹ºÝ¤Ë¤Ï¡¢²òÀÏÂоݤÎʸ»úÎó¤ò \fIstr\fP ¤Ë
63 »ØÄꤹ¤ë¡£Æ±¤¸Ê¸»úÎó¤Î²òÀϤò¹Ô¤¦¤½¤Î¸å¤Î¸Æ¤Ó½Ð¤·¤Ç¤Ï¡¢
64 \fIstr\fP ¤Ë¤Ï NULL ¤ò»ØÄꤹ¤ë¡£
66 \fIdelim\fP °ú¤¿ô¤Ë¤Ï¡¢²òÀϤ¹¤ëʸ»úÎó¤ò¥È¡¼¥¯¥ó¤Ë¶èÀÚ¤ëʸ»ú½¸¹ç¤ò
67 »ØÄꤹ¤ë¡£Æ±¤¸Ê¸»úÎó¤ò²òÀϤ¹¤ë°ìÏ¢¤Î¸Æ¤Ó½Ð¤·¤Ë¤ª¤¤¤Æ¡¢
68 \fIdelim\fP ¤Ë°ã¤¦Ê¸»úÎó¤ò»ØÄꤷ¤Æ¤â¤è¤¤¡£
71 ¤Î¤½¤ì¤¾¤ì¤Î¸Æ¤Ó½Ð¤·¤Ç¤Ï¡¢¼¡¤Î¥È¡¼¥¯¥ó¤ò
72 ³ÊǼ¤·¤¿ NULL ½ªÃ¼¤µ¤ì¤¿Ê¸»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤¬ÊÖ¤µ¤ì¤ë¡£
73 ¤³¤Îʸ»úÎó¤Ë¤Ï¶èÀÚ¤êʸ»ú¤Ï´Þ¤Þ¤ì¤Ê¤¤¡£
74 ¤³¤ì°Ê¾å¥È¡¼¥¯¥ó¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢NULL ¤¬ÊÖ¤µ¤ì¤ë¡£
76 ²òÀÏÂоݤÎʸ»úÎó¤Ë2¤Ä°Ê¾å¤Î¶èÀÚ¤êʸ»ú¤¬Ï¢Â³¤·¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¡¢
77 °ì¤Ä¤Î¶èÀÚ¤êʸ»ú¤È¤ß¤Ê¤µ¤ì¤ë¡£
78 ʸ»úÎó¤ÎÀèƬ¤äËöÈø¤Ë¤¢¤ë¶èÀÚ¤êʸ»ú¤Ï̵»ë¤µ¤ì¤ë¡£¸À¤¤´¹¤¨¤ë¤È¡¢
80 ¤¬ÊÖ¤¹¥È¡¼¥¯¥ó¤Ï¾ï¤Ë¶õ¤Ç¤Ê¤¤Ê¸»úÎó¤È¤Ê¤ë¡£
85 ¤Î¥ê¥¨¥ó¥È¥é¥ó¥ÈÈǤǤ¢¤ë¡£
86 \fIsaveptr\fP °ú¤¿ô¤Ï \fIchar *\fP ÊÑ¿ô¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ê¡¢
87 Ʊ¤¸Ê¸»úÎó¤Î²òÀϤò¹Ô¤¦
89 ¤Î¸Æ¤Ó½Ð¤·´Ö¤Ç½èÍý¾õ¶·¤òÊݸ¤¹¤ë¤¿¤á¤Ë
94 ¤òºÇ½é¤Ë¸Æ¤Ó½Ð¤¹ºÝ¤Ë¤Ï¡¢
96 ¤Ï²òÀÏÂоݤÎʸ»úÎó¤ò»Ø¤·¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤º¡¢
98 ¤ÎÃͤÏ̵»ë¤µ¤ì¤ë¡£¤½¤ì°Ê¹ß¤Î¸Æ¤Ó½Ð¤·¤Ç¤Ï¡¢
102 ¤ÏÁ°²ó¤Î¸Æ¤Ó½Ð¤·°Ê¹ßÊѹ¹¤·¤Ê¤¤¤è¤¦¤Ë¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
105 ¤Î¸Æ¤Ó½Ð¤·»þ¤Ë°Û¤Ê¤ë \fIsaveptr\fP °ú¤¿ô¤ò»ØÄꤹ¤ë¤³¤È¤Ç¡¢
106 °Û¤Ê¤ëʸ»úÎó¤Î²òÀϤòƱ»þ¤Ë¹Ô¤¦¤³¤È¤¬¤Ç¤¤ë¡£
111 ¤Ï¼¡¤Î¥È¡¼¥¯¥ó¤Ø¤Î¥Ý¥¤¥ó¥¿¤«¡¢
112 ¥È¡¼¥¯¥ó¤¬¤Ê¤±¤ì¤Ð NULL ¤òÊÖ¤¹¡£
116 SVr4, POSIX.1-2001, 4.3BSD, C89, C99.
121 ¤³¤ì¤é¤Î´Ø¿ô¤ò»È¤¦¤Î¤Ï¿µ½Å¤Ë¶ãÌ£¤¹¤ë¤³¤È¡£
122 »ÈÍѤ¹¤ë¾ì¹ç¤Ï¡¢°Ê²¼¤ÎÅÀ¤ËÃí°Õ¤¬É¬ÍפǤ¢¤ë¡£
124 ¤³¤ì¤é¤Î´Ø¿ô¤Ï¤½¤ÎºÇ½é¤Î°ú¿ô¤òÊѹ¹¤¹¤ë¡£
126 ¤³¤ì¤é¤Î´Ø¿ô¤Ï const ¤Êʸ»úÎó¤Ç¤Ï»È¤¨¤Ê¤¤¡£
128 ¶èÀÚ¤êʸ»ú¼«ÂΤϼº¤ï¤ì¤Æ¤·¤Þ¤¦¡£
131 ´Ø¿ô¤Ïʸ»úÎó¤Î²òÀϤËÀÅŪ¥Ð¥Ã¥Õ¥¡¤òÍѤ¤¤ë¤Î¤Ç¡¢¥¹¥ì¥Ã¥É¥»¡¼¥Õ¤Ç¤Ê¤¤¡£
132 ¤³¤ì¤¬ÌäÂê¤Ë¤Ê¤ë¾ì¹ç¤Ï
138 ¤òÍøÍѤ¹¤ë¥ë¡¼¥×¤òÆþ¤ì»Ò¤Ë¤·¤Æ»ÈÍѤ·¡¢
139 ʸ»úÎó¤ò2³¬ÁؤΥȡ¼¥¯¥ó¤Ëʬ³ä¤¹¤ë¤â¤Î¤Ç¤¢¤ë¡£
140 1ÈÖÌܤΥ³¥Þ¥ó¥É¥é¥¤¥ó°ú¤¿ô¤Ë¤Ï¡¢²òÀÏÂоݤÎʸ»úÎó¤ò»ØÄꤹ¤ë¡£
141 2ÈÖÌܤΰú¤¿ô¤Ë¤Ï¡¢Ê¸»úÎó¤ò¡ÖÂ礤ʡץȡ¼¥¯¥ó¤Ëʬ³ä¤¹¤ë¤¿¤á¤Ë
142 »ÈÍѤ¹¤ë¶èÀÚ¤êʸ»ú¤ò»ØÄꤹ¤ë¡£
143 3ÈÖÌܤΰú¤¿ô¤Ë¤Ï¡¢¡ÖÂ礤ʡץȡ¼¥¯¥ó¤òºÙ¤«¤¯Ê¬³ä¤¹¤ë¤¿¤á¤Ë
144 »ÈÍѤ¹¤ë¶èÀÚ¤êʸ»ú¤ò»ØÄꤹ¤ë¡£
147 ¤³¤Î¥×¥í¥°¥é¥à¤Î½ÐÎÏÎã¤ò°Ê²¼¤Ë¼¨¤¹¡£
151 .RB "$" " ./a.out \(aqa/bbb///cc;xxx:yyy:\(aq \(aq:;\(aq \(aq/\(aq"
162 .SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
170 main(int argc, char *argv[])
172 char *str1, *str2, *token, *subtoken;
173 char *saveptr1, *saveptr2;
177 fprintf(stderr, "Usage: %s string delim subdelim\\n",
182 for (j = 1, str1 = argv[1]; ; j++, str1 = NULL) {
183 token = strtok_r(str1, argv[2], &saveptr1);
186 printf("%d: %s\\n", j, token);
188 for (str2 = token; ; str2 = NULL) {
189 subtoken = strtok_r(str2, argv[3], &saveptr2);
190 if (subtoken == NULL)
192 printf("\t \-\-> %s\\n", subtoken);
201 ¤ò»È¤Ã¤¿ÊÌ¤Î¥×¥í¥°¥é¥àÎ㤬
202 .BR getaddrinfo_a (3)