Atol() - C Library function Program
Declaration :
|
1 |
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.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#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 :
|
1 2 |
String equivalent value of 12345678 = 12345678 String equivalent value of pritesh = 0 |
