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

  1. /* PRINTF.C illustrates output formatting with:
  2.  *      printf
  3.  *
  4.  * The rules for formatting also apply to cprintf, sprintf, vfprintf,
  5.  * vprintf, and vsprintf. For other examples of printf formatting,
  6.  * see EXTDIR.C (sprintf), VPRINTF (vprintf), TABLE.C (fprintf),
  7.  * ROTATE.C (printf), and IS.C (cprintf).
  8.  */
  9.  
  10. #include <stdio.h>
  11.  
  12. main()
  13. {
  14.     char ch = 'h', *string = "computer";
  15.     int count = 234, *ptr, hex = 0x10, oct = 010, dec = 10;
  16.     double fp = 251.7366;
  17.  
  18.     /* Display integers. */
  19.     printf("%d    %+d    %06d    %X    %x    %o\n\n",
  20.             count, count, count, count, count, count );
  21.  
  22.     /* Count characters printed. */
  23.     printf( "            V\n" );
  24.     printf( "1234567890123%n45678901234567890\n", &count );
  25.     printf( "Number of characters printed: %d\n\n", count );
  26.  
  27.     /* Display characters. */
  28.     printf( "%10c%5c\n\n", ch, ch );
  29.  
  30.     /* Display strings. */
  31.     printf( "%25s\n%25.4s\n\n", string, string );
  32.  
  33.     /* Display real numbers. */
  34.     printf( "%f    %.2f    %e    %E\n\n", fp, fp, fp, fp );
  35.  
  36.     /* Display in different radixes. */
  37.     printf( "%i    %i    %i\n\n", hex, oct, dec );
  38.  
  39.     /* Display pointers. */
  40.     ptr = &count;
  41.     printf( "%Np    %p    %Fp\n", ptr, (int far *)ptr, (int far *)ptr );
  42. }
  43.