📄 strtoul.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>strtoul</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_009_240"> </a>NAME</h4><blockquote>strtoul - convert string to an unsigned long</blockquote><h4><a name = "tag_000_009_241"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="stdlib.h.html">stdlib.h</a>>unsigned long int strtoul(const char *<i>str</i>, char *<i>*endptr</i>, int <i>base</i>);</code></pre></blockquote><h4><a name = "tag_000_009_242"> </a>DESCRIPTION</h4><blockquote>The<i>strtoul()</i>function converts the initial portion of the string pointed to by<i>str</i>to a type<b>unsigned long int</b>representation.First it decomposes the input string into three parts: an initial,possibly empty, sequence of white-space characters (as specified by<i><a href="isspace.html">isspace()</a></i>);a subject sequence interpreted as an integer representedin some radix determined by the value of<i>base</i>;and a final string of one or more unrecognised characters,including the terminating null byte of the input string.Then it attempts to convert the subject sequence to an unsigned integer,and returns the result.<p>If the value of<i>base</i>is 0, the expected form of the subject sequence is that of adecimal constant, octal constant or hexadecimal constant,any of which may be preceded by a + or - sign.A decimal constant begins with a non-zero digit, and consistsof a sequence of decimal digits.An octal constant consists of the prefix0 optionally followed by a sequence of the digits 0 to 7 only.A hexadecimal constant consists of the prefix0x or 0X followed by a sequence of the decimal digits and lettersa (or A) to f (or F) with values 10 to 15 respectively.<p>If the value of<i>base</i>is between 2 and 36, the expected form of the subject sequence isa sequence of letters and digits representing an integer with theradix specified by<i>base</i>,optionally preceded by a + or - sign.The letters from a (or A) to z (or Z) inclusiveare ascribed the values 10 to 35; only letters whose ascribedvalues are less than that of<i>base</i>are permitted.If the value of<i>base</i>is 16, the characters 0x or 0Xmay optionally precede the sequence of letters and digits,following the sign if present.<p>The subject sequence is defined as the longest initialsubsequence of the input string, starting with the firstnon-white-space character, that is of the expected form.The subject sequence contains no characters if the input stringis empty or consists entirely of white-space characters,or if the firstnon-white-space character is other than a sign or a permissibleletter or digit.<p>If the subject sequence has the expected form and the value of<i>base</i>is 0, the sequence of characters starting with the first digitis interpreted as an integer constant.If the subject sequence has the expected form and the value of<i>base</i>is between 2 and 36, it is used as the base for conversion,ascribing to each letter its value as given above.If the subject sequence begins with a minus sign, the valueresulting from the conversion is negated.A pointer to the final string is stored in the object pointed toby<i>endptr</i>,provided that<i>endptr</i>is not a null pointer.<p>In other than the POSIX locale, additional implementation-dependentsubject sequence forms may be accepted.<p>If the subject sequence is empty or does not have the expectedform, no conversion is performed; the value of<i>str</i>is stored in the object pointed to by<i>endptr</i>,provided that<i>endptr</i>is not a null pointer.<p>The<i>strtoul()</i>function will not change the setting of <b>errno</b>if successful.<p>Because 0 and ULONG_MAX are returned on error and are alsovalid returns on success, an application wishing to check for errorsituations should set<i>errno</i>to 0, then call<i>strtoul()</i>,then check<i>errno</i>.</blockquote><h4><a name = "tag_000_009_243"> </a>RETURN VALUE</h4><blockquote>Upon successful completion<i>strtoul()</i>returns the converted value, if any.If no conversion could be performed, 0 is returned and<i>errno</i>may be set to [EINVAL].If the correct value is outside the range of representablevalues, ULONG_MAX is returned and<i>errno</i>is set to [ERANGE].<br></blockquote><h4><a name = "tag_000_009_244"> </a>ERRORS</h4><blockquote>The<i>strtoul()</i>function will fail if:<dl compact><dt>[EINVAL]<dd>The value of<i>base</i>is not supported.<dt>[ERANGE]<dd>The value to be returned is not representable.</dl><p>The<i>strtoul()</i>function may fail if:<dl compact><dt>[EINVAL]<dd>No conversion could be performed.</dl></blockquote><h4><a name = "tag_000_009_245"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_009_246"> </a>APPLICATION USAGE</h4><blockquote>Unlike<i><a href="strtod.html">strtod()</a></i>and<i><a href="strtol.html">strtol()</a></i>,<i>strtoul()</i>must always return a non-negative number; so, using thereturn value of<i>strtoul()</i>for out-of-range numbers with<i>strtoul()</i>could cause more severe problems than just lossof precision if those numbers can ever be negative.</blockquote><h4><a name = "tag_000_009_247"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_009_248"> </a>SEE ALSO</h4><blockquote><i><a href="isalpha.html">isalpha()</a></i>,<i><a href="scanf.html">scanf()</a></i>,<i><a href="strtod.html">strtod()</a></i>,<i><a href="strtol.html">strtol()</a></i>,<i><a href="stdlib.h.html"><stdlib.h></a></i>.</blockquote><h4>DERIVATION</h4><blockquote>Derived from the ANSI C standard.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -