C library functions - atol ()
C standard library - <stdlib.h>
description
C library functions to convert a stringlong int atol (const char * str ) Parameters strpointed to a long integer (type long int type).
statement
The following is a statement atol () function.
long int atol(const char *str)
parameter
- str - a string to be converted to a long integer.
return value
This function returns the converted long integer if there is no implementation of an effective conversion, zero is returned.
Examples
The following example demonstrates atol () function is used.
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { long val; char str[20]; strcpy(str, "98993489"); val = atol(str); printf("字符串值 = %s, 长整型值 = %ld\n", str, val); strcpy(str, "w3cschool.cc"); val = atol(str); printf("字符串值 = %s, 长整型值 = %ld\n", str, val); return(0); }
Let's compile and run the above program, which will result in the following:
字符串值 = 98993489, 长整型值 = 98993489 字符串值 = w3cschool.cc, 长整型值 = 0