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);
The Third argument (base) can have a value of 0 or 2-32.
Example program.
| Top | Master Index | Keywords | Functions |