home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emx / test / conv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  755 b   |  36 lines

  1. /* conv.c (emx+gcc) */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. int main (int argc, char *argv[])
  8. {
  9.   char buf[100], *p;
  10.   int radix;
  11.   long n;
  12.   unsigned long u;
  13.  
  14.   if (argc == 1)
  15.     radix = 0;
  16.   else if (argc == 2)
  17.     radix = atoi (argv[1]);
  18.   else
  19.     {
  20.       printf ("Usage: conv [radix]\n");
  21.       return (1);
  22.     }
  23.   while (fgets (buf, sizeof (buf), stdin) != NULL)
  24.     {
  25.       p = strchr (buf, '\n');
  26.       if (p != NULL) *p = 0;
  27.       errno = 0;
  28.       n = strtol (buf, &p, radix);
  29.       printf ("strtol:  %ld, errno=%d, rest=<%s>\n", n, errno, p);
  30.       errno = 0;
  31.       u = strtoul (buf, &p, radix);
  32.       printf ("strtoul: %lu, errno=%d, rest=<%s>\n", u, errno, p);
  33.     }
  34.   return (0);
  35. }
  36.