C library function - atol()
Description
C library function *long int atol(const char str) Converts the string pointed to by the argument str The string pointed to by the argument is converted into a long integer (of type long int).
Declaration
The following is the declaration of the atol() function.
long int atol(const char *str)
Parameters
- str -- String to be converted to a long integer.
Return Value
The function returns the converted long integer; if no valid conversion was performed, it returns zero.
Example
The following example demonstrates the use of the atol() function.
#include
#include
#include
int main()
{
long val;
char str[20];
strcpy(str, "98993489");
val = atol(str);
printf("字符串值 = %s, 长整型值 = %ld\n", str, val);
strcpy(str, "runoob.com");
val = atol(str);
printf("字符串值 = %s, 长整型值 = %ld\n", str, val);
return(0);
}
Let's compile and run the above program, which will produce the following result:
字符串值 = 98993489, 长整型值 = 98993489
字符串值 = runoob.com, 长整型值 = 0
C Standard Library -