strtol

Solutions on MaxInterview for strtol by the best coders in the world

showing results for - "strtol"
Alessia
17 Oct 2019
1// definition: long int strtol (const char* str, char** endptr, int base);
2
3/* strtol example */
4#include <stdio.h>      /* printf */
5#include <stdlib.h>     /* strtol */
6
7int main ()
8{
9  char szNumbers[] = "2001 60c0c0 -1101110100110100100000 0x6fffff";
10  char * pEnd;
11  long int li1, li2, li3, li4;
12  li1 = strtol (szNumbers,&pEnd,10);
13  li2 = strtol (pEnd,&pEnd,16);
14  li3 = strtol (pEnd,&pEnd,2);
15  li4 = strtol (pEnd,NULL,0);
16  printf ("The decimal equivalents are: %ld, %ld, %ld and %ld.\n", li1, li2, li3, li4);
17  return 0;
18}