Atol() - C Library function Program
Declaration :
long int atol(const char *str)
Explanation :
Purpose | The C library function long int atol(const char *str) converts the string argument str to a long integer (type long int). |
Parameters | str ===> This is the string containing the representation of an integral number. |
Return Value | This function returns the converted integral number as a long int. If no valid conversion could be performed it returns zero. |
Header File | ctype.h |
Exception |
C Program : Example
See below example of atol() function.
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { long value; char str[20]; strcpy(str, "12345678"); value= atol(str); printf("\nString equivalent value of %s = %ld", str, value); strcpy(str, "pritesh"); value= atol(str); printf("\nString equivalent value of %s = %ld", str, value); return(0); }
Output :
String equivalent value of 12345678 = 12345678 String equivalent value of pritesh = 0