Function name : strtol
Header file : <stdlib.h>
Function prototype : long strtol(char *s,char **ptr,int radix);
Function : Used to convert a string into a long integer
Parameters : char *s is the string to be converted
char **ptr is a string pointer, used for error detection, and will terminate when encountering illegal characters; if ptr is not empty, the pointer to the character after the last character in the conversion will be stored at the location referenced by ptr.
int radix is the base method used
Return value : Returns the converted long integer
Program example : Use this function to convert the string 10000 into a long integer value according to different base modes.
#include<stdio.h>#include<stdlib.h>#include<time.h>intmain(void){char*a=100000;char*b=100000;charc[]=cd;printf(a=%d n,strtol(a,NULL,10));printf(b=%dn,strtol(b,NULL,2));printf(c=%dn,strtol(c,NULL,16)) ;return0;}
Running results
a=100000b=32c=205