C examples for stdlib.h:atol
function
<cstdlib> <stdlib.h>
Convert string to long integer
long int atol ( const char * str );
Parameter | Description |
---|---|
str | C-string representation of an integral number. |
On success, the function returns the converted integral number as long int value.
For non valid conversion, a zero value is returned.
#include <stdio.h> #include <stdlib.h> int main ()/*from ww w . ja v a 2s . c om*/ { long int li; char buffer[256]; printf ("Enter a long number: "); fgets (buffer, 256, stdin); li = atol(buffer); printf ("The value entered is %ld. Its double is %ld.\n",li,li*2); printf ("%ld.\n", atol("0")); printf ("%ld.\n", atol("111111110")); printf ("%ld.\n", atol("q")); return 0; }