#include <stdio.h>
#include <stdlib.h>

int main()
{
  long value;
  char *p, *endptr;

  p = "";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "@@@";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "   12345";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "12345@@@";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "10";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "12345";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "-12345";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "12345";
  value = strtol(p, &endptr, 10);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "-12345";
  value = strtol(p, &endptr, 10);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "01234";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "01234";
  value = strtol(p, &endptr, 8);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "1234";
  value = strtol(p, &endptr, 8);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0x1234abcd";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0x1234ABCD";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0X1234ABCD";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0x1234abcd";
  value = strtol(p, &endptr, 16);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0x1234ABCD";
  value = strtol(p, &endptr, 16);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "1234abcd";
  value = strtol(p, &endptr, 16);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "ghijkl";
  value = strtol(p, &endptr, 16);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "ghijkl";
  value = strtol(p, &endptr, 20);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "ghijkl";
  value = strtol(p, &endptr, 24);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0101";
  value = strtol(p, &endptr, 2);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "1010";
  value = strtol(p, &endptr, 2);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "1012";
  value = strtol(p, &endptr, 2);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "012345";
  value = strtol(p, &endptr, 5);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "43210";
  value = strtol(p, &endptr, 5);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "12345";
  value = strtol(p, &endptr, 5);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0";
  value = strtol(p, &endptr, 2);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "12345678";
  value = strtol(p, &endptr, 8);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0x1";
  value = strtol(p, &endptr, 2);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "01234";
  value = strtol(p, &endptr, 8);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "001234";
  value = strtol(p, &endptr, 8);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0x1234";
  value = strtol(p, &endptr, 8);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0x1234";
  value = strtol(p, &endptr, 10);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0789a";
  value = strtol(p, &endptr, 10);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0789a";
  value = strtol(p, &endptr, 16);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0defg";
  value = strtol(p, &endptr, 16);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0x0789a";
  value = strtol(p, &endptr, 16);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0x0defg";
  value = strtol(p, &endptr, 16);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "6789a";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0xdefg";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0x01234";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0x0defg";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "0678";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  p = "00678";
  value = strtol(p, &endptr, 0);
  printf("%ld %d\n", value, (int)(endptr - p));

  return 0;
}
