/* Kenneth L. Moore CIT 145 file: prints.c - printf examples. 22/01/02 06:48 */ #include void holdDOS(void){int mm;printf("enter any int");scanf("%d",&mm);} int main() { char c = 'A'; short s = 1235; int i = 12345; short hex = 0x0b52; short oct = 0571; unsigned u = 65535; long l = 12345678; float f = 5.555555; float ff = 1234000000.0; double ld = 3.1415926535897932; char str[] = "Brought to you by Kenneth L Moore."; int wid, prec; int mm; printf( "Sizes of vars: c=%d s=%d i=%d l=%d f=%d d=%d ld=%d str=%d\n\n", sizeof(c), sizeof(s), sizeof(i), sizeof(l), sizeof(f), sizeof(ld), sizeof(str) ); printf( "|%d|%d| no width specified \n", i, -i ); printf( "|%8d|%8d| width 8 specified \n", i, -i ); printf( "|%-8d|%-8d| left justified\n ", i, -i ); printf( "|%+8d|%+8d| force sign\n", i, -i ); printf( "|%-+8d|%-+8d| left, force sign\n ", i, -i); printf( "|%08d|%08d| leading zeros\n", i, -i ); printf( "|% 08d|% 08d| zero fill blank plus\n ", i, -i ); printf( "|%+08d|%+08d| zero fill sign\n", i, -i ); printf( "|%10.8d|%10.8d| force precision of 8 \n", i, -i ); wid = 14; printf( "|%*d| width variable at run time\n", wid, i ); wid = 9; printf( "|%*d| width variable at run time\n", wid, i ); printf( "|%14ld|%14ld| long int type\n", l, -l ); printf( "|%10hd|%10hd| short int type\n", s, -s ); printf( "|%u|%d| does signed/unsigned really matter?\n", u, u ); printf( "|%3d| will it truncate?\n", l ); printf( "|%x|%X|%.4x|%04x|%10.8X|%#x| hex\n", hex, hex, hex, hex, hex, hex ); printf( "|%o|%5o|%8.5o| octal\n", oct, oct, oct ); printf( "|%#o|%#x|%#d| octal, hex, integer\n", l, l, l ); holdDOS(); printf( "|%f|%.2f|%10f|%10.2f|%010.2f|%-10f|%+.2f| floats\n", f, f, f, f, f, f, f ); printf( "|%.3e|%E|%.3E|%12.5e| engineering notation\n", ff, ff, ff, ff ); printf( "|%g|%g|%12g| g formats\n", ff, 1234.0, ff ); printf( "|%.4g|%#.4g| force decimals\n", 1.1, 1.1 ); printf( "|%.10lg| long double\n", ld ); wid = 20; prec = 6; printf( "|%*.*lf| variable width and precision\n", wid, prec, ld ); printf( "|%c|%4c|%-4c|%04c| char formats \n", c, c, c, c ); printf( "|%s| full length\n", str ); printf( "|%40s|string in width 40\n", str ); printf( "|%5s|just 5 chars?\n", str ); printf( "|%.5s|just 4 chars\n", str ); printf( "|%-40s|left-justify in width 40 \n", str ); printf( "|%10.2s|1st 2 chars in width 10\n", str ); holdDOS(); return( 0 ); }