1<html lang="en"> 2<head> 3<title>wcstol - Untitled</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Untitled"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Stdlib.html#Stdlib" title="Stdlib"> 9<link rel="prev" href="wcstod.html#wcstod" title="wcstod"> 10<link rel="next" href="wcstoll.html#wcstoll" title="wcstoll"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<meta http-equiv="Content-Style-Type" content="text/css"> 13<style type="text/css"><!-- 14 pre.display { font-family:inherit } 15 pre.format { font-family:inherit } 16 pre.smalldisplay { font-family:inherit; font-size:smaller } 17 pre.smallformat { font-family:inherit; font-size:smaller } 18 pre.smallexample { font-size:smaller } 19 pre.smalllisp { font-size:smaller } 20 span.sc { font-variant:small-caps } 21 span.roman { font-family:serif; font-weight:normal; } 22 span.sansserif { font-family:sans-serif; font-weight:normal; } 23--></style> 24<link rel="stylesheet" type="text/css" href="../cs.css"> 25</head> 26<body> 27<div class="node"> 28<a name="wcstol"></a> 29<p> 30Next: <a rel="next" accesskey="n" href="wcstoll.html#wcstoll">wcstoll</a>, 31Previous: <a rel="previous" accesskey="p" href="wcstod.html#wcstod">wcstod</a>, 32Up: <a rel="up" accesskey="u" href="Stdlib.html#Stdlib">Stdlib</a> 33<hr> 34</div> 35 36<h3 class="section">2.41 <code>wcstol</code>—wide string to long</h3> 37 38<p><a name="index-wcstol-98"></a><a name="index-g_t_005fwcstol_005fr-99"></a><strong>Synopsis</strong> 39<pre class="example"> #include <wchar.h> 40 long wcstol(const wchar_t *<var>s</var>, wchar_t **<var>ptr</var>,int <var>base</var>); 41 42 long _wcstol_r(void *<var>reent</var>, 43 const wchar_t *<var>s</var>, wchar_t **<var>ptr</var>,int <var>base</var>); 44 45</pre> 46 <p><strong>Description</strong><br> 47The function <code>wcstol</code> converts the wide string <code>*</code><var>s</var> to 48a <code>long</code>. First, it breaks down the string into three parts: 49leading whitespace, which is ignored; a subject string consisting 50of characters resembling an integer in the radix specified by <var>base</var>; 51and a trailing portion consisting of zero or more unparseable characters, 52and always including the terminating null character. Then, it attempts 53to convert the subject string into a <code>long</code> and returns the 54result. 55 56 <p>If the value of <var>base</var> is 0, the subject string is expected to look 57like a normal C integer constant: an optional sign, a possible `<code>0x</code>' 58indicating a hexadecimal base, and a number. If <var>base</var> is between 592 and 36, the expected form of the subject is a sequence of letters 60and digits representing an integer in the radix specified by <var>base</var>, 61with an optional plus or minus sign. The letters <code>a</code>–<code>z</code> (or, 62equivalently, <code>A</code>–<code>Z</code>) are used to signify values from 10 to 35; 63only letters whose ascribed values are less than <var>base</var> are 64permitted. If <var>base</var> is 16, a leading <code>0x</code> is permitted. 65 66 <p>The subject sequence is the longest initial sequence of the input 67string that has the expected form, starting with the first 68non-whitespace character. If the string is empty or consists entirely 69of whitespace, or if the first non-whitespace character is not a 70permissible letter or digit, the subject string is empty. 71 72 <p>If the subject string is acceptable, and the value of <var>base</var> is zero, 73<code>wcstol</code> attempts to determine the radix from the input string. A 74string with a leading <code>0x</code> is treated as a hexadecimal value; a string with 75a leading 0 and no <code>x</code> is treated as octal; all other strings are 76treated as decimal. If <var>base</var> is between 2 and 36, it is used as the 77conversion radix, as described above. If the subject string begins with 78a minus sign, the value is negated. Finally, a pointer to the first 79character past the converted subject string is stored in <var>ptr</var>, if 80<var>ptr</var> is not <code>NULL</code>. 81 82 <p>If the subject string is empty (or not in acceptable form), no conversion 83is performed and the value of <var>s</var> is stored in <var>ptr</var> (if <var>ptr</var> is 84not <code>NULL</code>). 85 86 <p>The alternate function <code>_wcstol_r</code> is a reentrant version. The 87extra argument <var>reent</var> is a pointer to a reentrancy structure. 88 89 <p><br> 90<strong>Returns</strong><br> 91<code>wcstol</code> returns the converted value, if any. If no conversion was 92made, 0 is returned. 93 94 <p><code>wcstol</code> returns <code>LONG_MAX</code> or <code>LONG_MIN</code> if the magnitude of 95the converted value is too large, and sets <code>errno</code> to <code>ERANGE</code>. 96 97 <p><br> 98<strong>Portability</strong><br> 99<code>wcstol</code> is ANSI. 100 101 <p>No supporting OS subroutines are required. 102 103 <p><br> 104 105 </body></html> 106 107