strtol
long strtol ( const char * string, char** endptr, int radix ); | stdlib.h |
cplusplus.com |
Convert string to long integer.
Parses string interpreting its content as an integer value until a character
that can not be interpreted is found,
and returns a long int value.
Parameters.
initial chars Interpreted by strol as 0x hexadecimal: radix 16 0 octal: radix 8 any number from 1 to 9 decimal: radix 10
Return Value.
The converted long int value from the input string.
If conversion would cause overflow the result is LONG_MAX or LONG_MIN.
If an error occurs or no conversion can be made 0 is returned.
Portability.
Defined in ANSI-C.
Example.
/* strtol example */ #include <stdio.h> #include <stdlib.h> main () { char szInput [256]; char * pEnd; long l; printf ("Enter an integer value: "); gets (szInput); l = strtol (szInput,&pEnd,0); printf ("Value entered: %ld. Its double: %ld\n",l,l*2); return 0; }
See also.
atof,
strtol,
strtoul