Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

151 lines
7.0KB

  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>strtol (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="strtol (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="strtol (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="Stdlib.html#Stdlib" rel="up" title="Stdlib">
  16. <link href="strtoll.html#strtoll" rel="next" title="strtoll">
  17. <link href="strtod.html#strtod" rel="prev" title="strtod">
  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="strtol"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="strtoll.html#strtoll" accesskey="n" rel="next">strtoll</a>, Previous: <a href="strtod.html#strtod" accesskey="p" rel="prev">strtod</a>, Up: <a href="Stdlib.html#Stdlib" accesskey="u" rel="up">Stdlib</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="strtol_002c-strtol_005fl_002d_002d_002dstring-to-long"></a>
  54. <h3 class="section">2.38 <code>strtol</code>, <code>strtol_l</code>&mdash;string to long</h3>
  55. <a name="index-strtol"></a>
  56. <a name="index-strtol_005fl"></a>
  57. <a name="index-_005fstrtol_005fr"></a>
  58. <p><strong>Synopsis</strong>
  59. </p><div class="example">
  60. <pre class="example">#include &lt;stdlib.h&gt;
  61. long strtol(const char *restrict <var>s</var>, char **restrict <var>ptr</var>,
  62. int <var>base</var>);
  63. #include &lt;stdlib.h&gt;
  64. long strtol_l(const char *restrict <var>s</var>, char **restrict <var>ptr</var>,
  65. int <var>base</var>, locale_t <var>locale</var>);
  66. long _strtol_r(void *<var>reent</var>, const char *restrict <var>s</var>,
  67. char **restrict <var>ptr</var>,int <var>base</var>);
  68. </pre></div>
  69. <p><strong>Description</strong><br>
  70. The function <code>strtol</code> converts the string <code>*<var>s</var></code> to
  71. a <code>long</code>. First, it breaks down the string into three parts:
  72. leading whitespace, which is ignored; a subject string consisting
  73. of characters resembling an integer in the radix specified by <var>base</var>;
  74. and a trailing portion consisting of zero or more unparseable characters,
  75. and always including the terminating null character. Then, it attempts
  76. to convert the subject string into a <code>long</code> and returns the
  77. result.
  78. </p>
  79. <p>If the value of <var>base</var> is 0, the subject string is expected to look
  80. like a normal C integer constant: an optional sign, a possible &lsquo;<code>0x</code>&rsquo;
  81. indicating a hexadecimal base, and a number. If <var>base</var> is between
  82. 2 and 36, the expected form of the subject is a sequence of letters
  83. and digits representing an integer in the radix specified by <var>base</var>,
  84. with an optional plus or minus sign. The letters <code>a</code>&ndash;<code>z</code> (or,
  85. equivalently, <code>A</code>&ndash;<code>Z</code>) are used to signify values from 10 to 35;
  86. only letters whose ascribed values are less than <var>base</var> are
  87. permitted. If <var>base</var> is 16, a leading <code>0x</code> is permitted.
  88. </p>
  89. <p>The subject sequence is the longest initial sequence of the input
  90. string that has the expected form, starting with the first
  91. non-whitespace character. If the string is empty or consists entirely
  92. of whitespace, or if the first non-whitespace character is not a
  93. permissible letter or digit, the subject string is empty.
  94. </p>
  95. <p>If the subject string is acceptable, and the value of <var>base</var> is zero,
  96. <code>strtol</code> attempts to determine the radix from the input string. A
  97. string with a leading <code>0x</code> is treated as a hexadecimal value; a string with
  98. a leading 0 and no <code>x</code> is treated as octal; all other strings are
  99. treated as decimal. If <var>base</var> is between 2 and 36, it is used as the
  100. conversion radix, as described above. If the subject string begins with
  101. a minus sign, the value is negated. Finally, a pointer to the first
  102. character past the converted subject string is stored in <var>ptr</var>, if
  103. <var>ptr</var> is not <code>NULL</code>.
  104. </p>
  105. <p>If the subject string is empty (or not in acceptable form), no conversion
  106. is performed and the value of <var>s</var> is stored in <var>ptr</var> (if <var>ptr</var> is
  107. not <code>NULL</code>).
  108. </p>
  109. <p><code>strtol_l</code> is like <code>strtol</code> but performs the conversion based on the
  110. locale specified by the locale object locale. If <var>locale</var> is
  111. LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined.
  112. </p>
  113. <p>The alternate function <code>_strtol_r</code> is a reentrant version. The
  114. extra argument <var>reent</var> is a pointer to a reentrancy structure.
  115. </p>
  116. <br>
  117. <p><strong>Returns</strong><br>
  118. <code>strtol</code>, <code>strtol_l</code> return the converted value, if any. If no
  119. conversion was made, 0 is returned.
  120. </p>
  121. <p><code>strtol</code>, <code>strtol_l</code> return <code>LONG_MAX</code> or <code>LONG_MIN</code> if the
  122. magnitude of the converted value is too large, and sets <code>errno</code>
  123. to <code>ERANGE</code>.
  124. </p>
  125. <br>
  126. <p><strong>Portability</strong><br>
  127. <code>strtol</code> is ANSI.
  128. <code>strtol_l</code> is a GNU extension.
  129. </p>
  130. <p>No supporting OS subroutines are required.
  131. </p>
  132. <br>
  133. <hr>
  134. <div class="header">
  135. <p>
  136. Next: <a href="strtoll.html#strtoll" accesskey="n" rel="next">strtoll</a>, Previous: <a href="strtod.html#strtod" accesskey="p" rel="prev">strtod</a>, Up: <a href="Stdlib.html#Stdlib" accesskey="u" rel="up">Stdlib</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>
  137. </div>
  138. </body>
  139. </html>