diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/string%2Fwide%2Fwcstol.html | |
new repository
Diffstat (limited to 'devdocs/c/string%2Fwide%2Fwcstol.html')
| -rw-r--r-- | devdocs/c/string%2Fwide%2Fwcstol.html | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/devdocs/c/string%2Fwide%2Fwcstol.html b/devdocs/c/string%2Fwide%2Fwcstol.html new file mode 100644 index 00000000..d9da4632 --- /dev/null +++ b/devdocs/c/string%2Fwide%2Fwcstol.html @@ -0,0 +1,65 @@ + <h1 id="firstHeading" class="firstHeading">wcstol, wcstoll</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><wchar.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c95 t-until-c99"> <td><pre data-language="c">long wcstol( const wchar_t * str, wchar_t ** str_end, int base );</pre></td> <td class="t-dcl-nopad"> </td> <td> +<span class="t-mark-rev t-since-c95">(since C95)</span> <br><span class="t-mark-rev t-until-c99">(until C99)</span> +</td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">long wcstol( const wchar_t * restrict str, wchar_t ** restrict str_end, + int base );</pre> +</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">long long wcstoll( const wchar_t * restrict str, wchar_t ** restrict str_end, + int base );</pre> +</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> </table> <p>Interprets an integer value in a wide string pointed to by <code>str</code>.</p> +<p>Discards any whitespace characters (as identified by calling <a href="iswspace" title="c/string/wide/iswspace"><code>iswspace</code></a>) until the first non-whitespace character is found, then takes as many characters as possible to form a valid <i>base-n</i> (where n=<code>base</code>) integer number representation and converts them to an integer value. The valid integer value consists of the following parts:</p> +<ul> +<li> <span class="t-mark">(optional)</span> plus or minus sign </li> +<li> <span class="t-mark">(optional)</span> prefix (<code>0</code>) indicating octal base (applies only when the base is <code>8</code> or <code>0</code>) </li> +<li> <span class="t-mark">(optional)</span> prefix (<code>0x</code> or <code>0X</code>) indicating hexadecimal base (applies only when the base is <code>16</code> or <code>0</code>) </li> +<li> a sequence of digits </li> +</ul> <p>The set of valid values for base is <code>{0,2,3,...,36}.</code> The set of valid digits for base-<code>2</code> integers is <code>{0,1},</code> for base-<code>3</code> integers is <code>{0,1,2},</code> and so on. For bases larger than <code>10</code>, valid digits include alphabetic characters, starting from <code>Aa</code> for base-<code>11</code> integer, to <code>Zz</code> for base-<code>36</code> integer. The case of the characters is ignored.</p> +<p>Additional numeric formats may be accepted by the currently installed C <a href="../../locale/setlocale" title="c/locale/setlocale">locale</a>.</p> +<p>If the value of <code>base</code> is <code>0</code>, the numeric base is auto-detected: if the prefix is <code>0</code>, the base is octal, if the prefix is <code>0x</code> or <code>0X</code>, the base is hexadecimal, otherwise the base is decimal.</p> +<p>If the minus sign was part of the input sequence, the numeric value calculated from the sequence of digits is negated as if by <a href="../../language/operator_arithmetic#Unary_arithmetic" title="c/language/operator arithmetic">unary minus</a> in the result type.</p> +<p>The functions sets the pointer pointed to by <code>str_end</code> to point to the wide character past the last character interpreted. If <code>str_end</code> is a null pointer, it is ignored.</p> +<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> str </td> <td> - </td> <td> pointer to the null-terminated wide string to be interpreted </td> +</tr> <tr class="t-par"> <td> str_end </td> <td> - </td> <td> pointer to a pointer to wide character </td> +</tr> <tr class="t-par"> <td> base </td> <td> - </td> <td> <i>base</i> of the interpreted integer value </td> +</tr> +</table> <h3 id="Return_value"> Return value</h3> <p>Integer value corresponding to the contents of <code>str</code> on success. If the converted value falls out of range of corresponding return type, range error occurs and <code><a href="../../types/limits" title="c/types/limits">LONG_MAX</a></code>, <code><a href="../../types/limits" title="c/types/limits">LONG_MIN</a></code>, <code><a href="../../types/limits" title="c/types/limits">LLONG_MAX</a></code> or <code><a href="../../types/limits" title="c/types/limits">LLONG_MIN</a></code> is returned. If no conversion can be performed, <code>0</code> is returned.</p> +<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <stdio.h> +#include <errno.h> +#include <wchar.h> + +int main(void) +{ + const wchar_t *p = L"10 200000000000000000000000000000 30 -40"; + printf("Parsing L'%ls':\n", p); + wchar_t *end; + for (long i = wcstol(p, &end, 10); + p != end; + i = wcstol(p, &end, 10)) + { + printf("'%.*ls' -> ", (int)(end-p), p); + p = end; + if (errno == ERANGE){ + printf("range error, got "); + errno = 0; + } + printf("%ld\n", i); + } +}</pre></div> <p>Output:</p> +<div class="text source-text"><pre data-language="c">Parsing L'10 200000000000000000000000000000 30 -40': +'10' -> 10 +' 200000000000000000000000000000' -> range error, got 9223372036854775807 +' 30' -> 30 +' -40' -> -40</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul><li> 7.29.4.1.2 The wcstol, wcstoll, wcstoul, and wcstoull functions (p: 429-430) </li></ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul><li> 7.24.4.1.2 The wcstol, wcstoll, wcstoul, and wcstoull functions (p: 375-376) </li></ul> +</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="../byte/strtol" title="c/string/byte/strtol"> <span class="t-lines"><span>strtol</span><span>strtoll</span></span></a></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> converts a byte string to an integer value <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><a href="wcstoul" title="c/string/wide/wcstoul"> <span class="t-lines"><span>wcstoul</span><span>wcstoull</span></span></a></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c95">(C95)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> converts a wide string to an unsigned integer value <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/string/wide/wcstol" title="cpp/string/wide/wcstol">C++ documentation</a></span> for <code>wcstol, wcstoll</code> </td> +</tr> </table> <div class="_attribution"> + <p class="_attribution-p"> + © cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br> + <a href="https://en.cppreference.com/w/c/string/wide/wcstol" class="_attribution-link">https://en.cppreference.com/w/c/string/wide/wcstol</a> + </p> +</div> |
