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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  return 0;
}
