/* conv.c (emx+gcc) */

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

int main (int argc, char *argv[])
{
  char buf[100], *p;
  int radix;
  long s;
  unsigned long u;
  long long sll;
  unsigned long long ull;

  if (argc == 1)
    radix = 0;
  else if (argc == 2)
    radix = atoi (argv[1]);
  else
    {
      printf ("Usage: conv [radix]\n");
      return 1;
    }
  for (;;)
    {
      printf ("Input: "); fflush (stdout);
      if (fgets (buf, sizeof (buf), stdin) == NULL)
        break;
      p = strchr (buf, '\n');
      if (p != NULL) *p = 0;
      errno = 0;
      s = strtol (buf, &p, radix);
      printf ("strtol:  %ld, errno=%d, rest=<%s>\n", s, errno, p);
      errno = 0;
      u = strtoul (buf, &p, radix);
      printf ("strtoul: %lu, errno=%d, rest=<%s>\n", u, errno, p);

      errno = 0;
      sll = _strtoll (buf, &p, radix);
      printf ("_strtoll:  %Ld, errno=%d, rest=<%s>\n", sll, errno, p);
      errno = 0;
      ull = _strtoull (buf, &p, radix);
      printf ("_strtoull: %Lu, errno=%d, rest=<%s>\n", ull, errno, p);
    }
  return 0;
}
