home *** CD-ROM | disk | FTP | other *** search
- main() /* printf2.c -- illustration of printf()'s formatting capabilities */
- {
- int i;
- float f;
- char *s;
- i = 123;
- printf("begin\t%d\tend\n", i);
- printf("begin\t%04d\tend\n", i);
- printf("begin\t%-02d\tend\n", i);
- printf("begin\t%o\tend\n", i);
- printf("begin\t%x\tend\n", i);
- printf("begin\t%u\tend\n", i);
- printf("begin\t%-12d\tend\n", i);
- printf("begin\t%12d\tend\n", i);
-
- f = 12.34;
- printf("begin\t%f\tend\n", f);
- printf("begin\t%.1f\tend\n", f);
- printf("begin\t%06.1f\tend\n", f);
- printf("begin\t%-6.1f\tend\n", f);
-
- s = "ABCDEFGHIJKLMNOP";
- printf("begin\t%s\tend\n", s);
- printf("begin\t%12s\tend\n", s);
- printf("begin\t%-12s\tend\n", s);
- printf("begin\t%.12s\tend\n",s);
- printf("begin\t%20s\tend\n", s);
- printf("begin\t%20.12s\tend\n", s);
- printf("begin\t%-20.12s\tend\n", s);
- }