strtol will convert a string to a long integer. An important feature of this function is the ability to accept data in various number bases and convert to decimal. If you are just working with decimal numbers, atoi is probably an easer function to use.
Library: stdlib.h Prototype: long int strtol(const char *sptr, char **endptr, int base); Syntax: char String[]="ff"; /* string to convert */ int Base=16; /* Base 16 */ long int Ans; /* Result */ Ans = strtol(String, NULL, Base);
initial chars Interpreted by strol as 0x hexadecimal: radix 16 0 octal: radix 8 any number from 1 to 9 decimal: radix 10
The Third argument (base) can have a value of 0 or 2-32.
atoi String to integer conversion.
atof String to floating point conversion.
atol String to long integer conversion.
strtod String to double conversion.
strtoul String to unsigned long integer conversion.
Top | Master Index | Keywords | Functions |