c strtol code example

Example 1: strtol

// definition: long int strtol (const char* str, char** endptr, int base);

/* strtol example */
#include       /* printf */
#include      /* strtol */

int main ()
{
  char szNumbers[] = "2001 60c0c0 -1101110100110100100000 0x6fffff";
  char * pEnd;
  long int li1, li2, li3, li4;
  li1 = strtol (szNumbers,&pEnd,10);
  li2 = strtol (pEnd,&pEnd,16);
  li3 = strtol (pEnd,&pEnd,2);
  li4 = strtol (pEnd,NULL,0);
  printf ("The decimal equivalents are: %ld, %ld, %ld and %ld.\n", li1, li2, li3, li4);
  return 0;
}

Example 2: strtol in c

long int strtol(const char *str, char **endptr, int base)

Example 3: strtol c

long strtol( const char * theString, char ** end, int base );

Tags:

Misc Example