home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / learn / numtoa.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-25  |  1.0 KB  |  42 lines

  1. /* NUMTOA.C illustrates number to string conversion functions including:
  2.  *      itoa            ltoa            ultoa
  3.  */
  4.  
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7.  
  8. main()
  9. {
  10.     int  base, i;
  11.     long l;
  12.     unsigned long ul;
  13.     char buffer[60];
  14.  
  15.     printf( "Enter an integer: " );
  16.     scanf( "%d", &i );
  17.     for( base =  2; base <= 16; base += 2 )
  18.     {
  19.         itoa( i, buffer, base );
  20.         if( base != 10 )
  21.             printf( "%d in base %d is: %s\n", i, base, buffer );
  22.     }
  23.  
  24.     printf( "Enter a long integer: " );
  25.     scanf( "%ld", &l );
  26.     for( base =  2; base <= 16; base += 2 )
  27.     {
  28.         ltoa( l, buffer, base );
  29.         if( base != 10 )
  30.             printf( "%ld in base %d is: %s\n", l, base, buffer );
  31.     }
  32.  
  33.     printf( "Enter an unsigned long integer: " );
  34.     scanf( "%lu", &ul );
  35.     for( base =  2; base <= 16; base += 2 )
  36.     {
  37.         ultoa( ul, buffer, base );
  38.         if( base != 10 )
  39.             printf( "%lu in base %d is: %s\n", ul, base, buffer );
  40.     }
  41. }
  42.