home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c025 / 1.ddi / PRINTF2.C < prev    next >
Encoding:
Text File  |  1985-01-24  |  831 b   |  31 lines

  1. main()    /* printf2.c -- illustration of printf()'s formatting capabilities */
  2. {
  3. int i;
  4. float f;
  5. char *s;
  6. i = 123;
  7.     printf("begin\t%d\tend\n", i);
  8.     printf("begin\t%04d\tend\n", i);
  9.     printf("begin\t%-02d\tend\n", i);
  10.     printf("begin\t%o\tend\n", i);
  11.     printf("begin\t%x\tend\n", i);
  12.     printf("begin\t%u\tend\n", i);
  13.     printf("begin\t%-12d\tend\n", i);
  14.     printf("begin\t%12d\tend\n", i);
  15.  
  16. f = 12.34;
  17.     printf("begin\t%f\tend\n", f);
  18.     printf("begin\t%.1f\tend\n", f);
  19.     printf("begin\t%06.1f\tend\n", f);
  20.     printf("begin\t%-6.1f\tend\n", f);
  21.  
  22. s = "ABCDEFGHIJKLMNOP";
  23.     printf("begin\t%s\tend\n", s);
  24.     printf("begin\t%12s\tend\n", s);
  25.     printf("begin\t%-12s\tend\n", s);
  26.     printf("begin\t%.12s\tend\n",s);
  27.     printf("begin\t%20s\tend\n", s);
  28.     printf("begin\t%20.12s\tend\n", s);
  29.     printf("begin\t%-20.12s\tend\n", s);
  30. }
  31.