You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 satır
5.9KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>strtok (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="strtok (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="strtok (The Red Hat newlib C Library)">
  9. <meta name="resource-type" content="document">
  10. <meta name="distribution" content="global">
  11. <meta name="Generator" content="makeinfo">
  12. <link href="index.html#Top" rel="start" title="Top">
  13. <link href="Document-Index.html#Document-Index" rel="index" title="Document Index">
  14. <link href="Document-Index.html#SEC_Contents" rel="contents" title="Table of Contents">
  15. <link href="Strings.html#Strings" rel="up" title="Strings">
  16. <link href="strupr.html#strupr" rel="next" title="strupr">
  17. <link href="strstr.html#strstr" rel="prev" title="strstr">
  18. <style type="text/css">
  19. <!--
  20. a.summary-letter {text-decoration: none}
  21. blockquote.indentedblock {margin-right: 0em}
  22. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  23. blockquote.smallquotation {font-size: smaller}
  24. div.display {margin-left: 3.2em}
  25. div.example {margin-left: 3.2em}
  26. div.lisp {margin-left: 3.2em}
  27. div.smalldisplay {margin-left: 3.2em}
  28. div.smallexample {margin-left: 3.2em}
  29. div.smalllisp {margin-left: 3.2em}
  30. kbd {font-style: oblique}
  31. pre.display {font-family: inherit}
  32. pre.format {font-family: inherit}
  33. pre.menu-comment {font-family: serif}
  34. pre.menu-preformatted {font-family: serif}
  35. pre.smalldisplay {font-family: inherit; font-size: smaller}
  36. pre.smallexample {font-size: smaller}
  37. pre.smallformat {font-family: inherit; font-size: smaller}
  38. pre.smalllisp {font-size: smaller}
  39. span.nolinebreak {white-space: nowrap}
  40. span.roman {font-family: initial; font-weight: normal}
  41. span.sansserif {font-family: sans-serif; font-weight: normal}
  42. ul.no-bullet {list-style: none}
  43. -->
  44. </style>
  45. </head>
  46. <body lang="en">
  47. <a name="strtok"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="strupr.html#strupr" accesskey="n" rel="next">strupr</a>, Previous: <a href="strstr.html#strstr" accesskey="p" rel="prev">strstr</a>, Up: <a href="Strings.html#Strings" accesskey="u" rel="up">Strings</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  51. </div>
  52. <hr>
  53. <a name="strtok_002c-strtok_005fr_002c-strsep_002d_002d_002dget-next-token-from-a-string"></a>
  54. <h3 class="section">5.42 <code>strtok</code>, <code>strtok_r</code>, <code>strsep</code>&mdash;get next token from a string</h3>
  55. <a name="index-strtok"></a>
  56. <a name="index-strtok_005fr"></a>
  57. <a name="index-strsep"></a>
  58. <p><strong>Synopsis</strong>
  59. </p><div class="example">
  60. <pre class="example">#include &lt;string.h&gt;
  61. char *strtok(char *restrict <var>source</var>,
  62. const char *restrict <var>delimiters</var>);
  63. char *strtok_r(char *restrict <var>source</var>,
  64. const char *restrict <var>delimiters</var>,
  65. char **<var>lasts</var>);
  66. char *strsep(char **<var>source_ptr</var>, const char *<var>delimiters</var>);
  67. </pre></div>
  68. <p><strong>Description</strong><br>
  69. The <code>strtok</code> function is used to isolate sequential tokens in a
  70. null-terminated string, <code>*<var>source</var></code>. These tokens are delimited
  71. in the string by at least one of the characters in <code>*<var>delimiters</var></code>.
  72. The first time that <code>strtok</code> is called, <code>*<var>source</var></code> should be
  73. specified; subsequent calls, wishing to obtain further tokens from
  74. the same string, should pass a null pointer instead. The separator
  75. string, <code>*<var>delimiters</var></code>, must be supplied each time and may
  76. change between calls.
  77. </p>
  78. <p>The <code>strtok</code> function returns a pointer to the beginning of each
  79. subsequent token in the string, after replacing the separator
  80. character itself with a null character. When no more tokens remain,
  81. a null pointer is returned.
  82. </p>
  83. <p>The <code>strtok_r</code> function has the same behavior as <code>strtok</code>, except
  84. a pointer to placeholder <code>*<var>lasts</var></code> must be supplied by the caller.
  85. </p>
  86. <p>The <code>strsep</code> function is similar in behavior to <code>strtok</code>, except
  87. a pointer to the string pointer must be supplied <code><var>source_ptr</var></code> and
  88. the function does not skip leading delimiters. When the string starts
  89. with a delimiter, the delimiter is changed to the null character and
  90. the empty string is returned. Like <code>strtok_r</code> and <code>strtok</code>, the
  91. <code>*<var>source_ptr</var></code> is updated to the next character following the
  92. last delimiter found or NULL if the end of string is reached with
  93. no more delimiters.
  94. </p>
  95. <br>
  96. <p><strong>Returns</strong><br>
  97. <code>strtok</code>, <code>strtok_r</code>, and <code>strsep</code> all return a pointer to the
  98. next token, or <code>NULL</code> if no more tokens can be found. For
  99. <code>strsep</code>, a token may be the empty string.
  100. </p>
  101. <br>
  102. <p><strong>Notes</strong><br>
  103. <code>strtok</code> is unsafe for multi-threaded applications. <code>strtok_r</code>
  104. and <code>strsep</code> are thread-safe and should be used instead.
  105. </p>
  106. <br>
  107. <p><strong>Portability</strong><br>
  108. <code>strtok</code> is ANSI C.
  109. <code>strtok_r</code> is POSIX.
  110. <code>strsep</code> is a BSD extension.
  111. </p>
  112. <p><code>strtok</code>, <code>strtok_r</code>, and <code>strsep</code> require no supporting OS subroutines.
  113. </p>
  114. <br>
  115. <hr>
  116. <div class="header">
  117. <p>
  118. Next: <a href="strupr.html#strupr" accesskey="n" rel="next">strupr</a>, Previous: <a href="strstr.html#strstr" accesskey="p" rel="prev">strstr</a>, Up: <a href="Strings.html#Strings" accesskey="u" rel="up">Strings</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  119. </div>
  120. </body>
  121. </html>