atof.3
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 3 代码 · 共 220 行
3
220 行
.\" SCCSID: @(#)atof.3 2.5 8/10/87.TH atof 3 .SH Nameatof, atoi, atol, strtol, strtoul, strtod \- convert ASCII to numbers.SH Syntax.nf.B #include <math.h>.PP.B double atof(\fInptr\fP).B char *\fInptr\fP;.PP.B atoi(\fInptr\fP).B char *\fInptr\fP;.PP.B long atol(\fInptr\fP).B char *\fInptr\fP;.PP.B long strtol(\fInptr\fP, \fIeptr\fP, \fIbase\fP).B char *\fInptr\fP, **\fIeptr\fP;.B int \fIbase\fP;.PP.B unsigned long strtoul(\fInptr\fP, \fIeptr\fP, \fIbase\fP).B char *\fInptr\fP, **\fIeptr\fP;.B int \fIbase\fP;.PP.B double strtod (\fInptr\fP, \fIeptr\fP).B char *\fInptr\fP, **\fIeptr\fP;.PP.B unsigned long strtoul(\fInptr, eptr, base\fP).B char *\fInptr, **eptr\fP;.B int \fIbase\fP;.fi.SH Description.NXR "atof subroutine (standard C)".NXR "atoi subroutine".NXR "atol subroutine".NXR "strtol subroutine".NXR "strtod subroutine".NXR "atof subroutine (standard C) " "isalpha subroutine".NXR "isalpha subroutine" "atof subroutine (standard C)".NXR "ASCII string" "converting to numbers"These functions convert a string pointed to by.I nptrto floating, integer, and long integer representation respectively.The first unrecognized character ends the string..PPThe.PN atoffunction recognizes (in order), an optional string of spaces, an optional sign, a string of digits optionally containing a radixcharacter, an optional `e' or `E', and then an optionally signed integer..PPThe.PN atoiand.PN atolfunctions recognize (in order), an optional string of spaces, an optional sign, then a string of digits..PPThe.PN strtolfunctionreturns as a long integer, the value represented by the character string.I nstr.The string is scanned up to the first characterinconsistent with the .I base.Leading white-spacecharacters are ignored..PPIf the value of .I eptris not (char **) NULL, a pointer to the character terminating the scan is returned in.I **eptr. If no integer can be formed, .I **eptris set to .I nstr ,and zero is returned..PPIf \fIbase\fP is positive and not greater than 36,it is used as the base for conversion. After anoptional leading sign, leading zeros are ignored,and 0x or 0X is ignored if \fIbase\fP is 16..PPIf \fIbase\fP is zero, the string itself determines the base thus: After an optional leading sign, aleading zero indicates octal conversion, and a leading 0x or 0X hexadecimal conversion.Otherwise, decimal conversion is used..PPTruncation from \fIlong\fR to \fIint\fR can take place upon assignment, or by an explicit cast..PPThe.PN strtoulfunction is the same as.PN strtolexcept that.PN strtoulreturns, as an unsigned long integer, the value represented by thecharacter string.I nstr..PPThe.PN strtodfunction returns as a double-precision floating point number,the value represented by the character string pointed to by.I nptr.The string is scanned up to the first unrecognized character..PPThe.PN strtod function recognizes an optional string of white-space characters,as defined by \fIisspace\fP in.PN ctype ,then an optional sign, then a string of digitsoptionally containing a radix character, then an optional \fIe\fR or \fIE\fR followed by an optional sign or space, followed by an integer..PPIf the value of.I eptris not (char **)NULL, a pointer to the characterterminating the scan is returned in the location pointed to by.I eptr.If no number can be formed, \fI*eptr\fP is set to \fInptr\fP,and zero is returned..PPThe radix character for.PN atofand.PN strtodis that defined by the last successful call to.PN setlocalecategory.PN LC_NUMERIC .If.PN setlocalecategory.PN LC_NUMERIChas not been called successfully, or if the radix character is not defined for a supported language, the radix character is defined as a period (.)..SS International Environment.IP LC_CTYPE 15If this environment variable is set and valid,.PN strtoduses the international language database named in the definition todetermine character classification rules..IP LC_NUMERIC 15If this environment is set and valid, .PN atofand.PN strtoduse the international language database named in the definition todetermine radix character rules..IP LANG 15If this environment variable is set and valid .PN atofand.PN strtoduse the international language database named in the definition todetermine collation and character classification rules. If.PN LC_CTYPEor .PN LC_NUMERIC is defined, their definition supercedes the definition ofLANG..SH DiagnosticsThe.PN atoffunction returns HUGEif an overflow occurs, and a 0 value if anunderflow occurs, and sets.I errnoto ERANGE.HUGE is defined in.PN <math.h>..PPThe .PN atoi function returns INT_MAX or INT_MIN (according tothe sign of the value) and sets .I errno to ERANGE, if the correctvalue is outside the range of values that can be represented..PPThe .PN atol function returns LONG_MAX or LONG_MIN (according tothe sign of the value) and sets .I errno to ERANGE, if the correctvalue is outside the range of values that can be represented..PPThe.PN strtolfunction returns LONG_MAX or LONG_MIN (according to the sign of the value) and sets.I errnoto ERANGE, if the correct value is outside the range of values that can be represented..PPThe.PN strtoulfunction returns ULONG_MAX and sets.I errnoto ERANGE, if the correct value is outside the range of values that canbe represented..PPThe.PN strtodfunction returns HUGE(according to the sign of the value), and sets .I errnoto ERANGE if the correct value would cause overflow. A 0 is returned and.I errnois set to ERANGE if the correct value would cause underflow..SH See Alsoctype(3), setlocale(3), scanf(3s), environ(5int)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?