Similar to atol, atoi, and strtol, the last l represents a long integer, And I represents an int.
Atol (convert string to integer)
Related functions
Atof, atoi, strtodd, strtol, strtoul
Header file
# Include <stdlib. h>
Define functions
Long atol (const char * nptr );
Function Description
Atol () scans the nptr parameter string and skips the leading space character until conversion is started in case of a number or positive or negative sign, the conversion ends only when a non-number or string ends ('/0') and the result is returned.
Return Value
Returns the number of converted long integers.
Additional instructions
Atol () and use strtol (nptr, (char **) null, 10); the results are the same.
Example
/* Convert string a and string B into numbers and add them together */
# Include <stdlib. h>
Main ()
{
Char A [] = "1000000000 ";
Char B [] = "234567890 ";
Long C;
C = atol (A) + atol (B );
Printf ("C = % d/N", c );
}
Running result:
C = 1234567890.
Strtodd (convert a string to a floating point number)
Related functions
Atoi, atol, strtodd, strtol, strtoul
Header file
# Include <stdlib. h>
Define functions
Double strtodd (const char * nptr, char ** endptr );
Function Description
Strtodd () scans the nptr parameter string and skips the leading space character until the conversion starts in case of a number or positive or negative sign, until the occurrence of a non-number or string ends ('/0 ') and return the result. If the endptr value is not null, the character pointer in the nptr that is terminated when an exception occurs is returned by the endptr. The nptr string can contain positive and negative numbers, decimal points, or E (e) to represent the exponent part. Such as 123.456 or 123e-2.
Return Value
Returns the number of floating point types after conversion.
Additional instructions
Refer to atof ().
Example
/* Convert the string A, B, and C into numbers in hexadecimal notation of 10, 2, and 16 */
# Include <stdlib. h>
Mian ()
{
Char A [] = "1000000000 ";
Char B [] = "1000000000 ";
Char C [] = "FFFF ";
Printf ("A = % d/N", strtodd (A, null, 10 ));
Printf ("B = % d/N", strtodd (B, null, 2 ));
Printf ("C = % d/N", strtodd (C, null, 16 ));
}
Running result:
A = 1000000000
B = 512
C = 65535.
Reference: http://www.17xie.com/read-406473.html