24.7.1 Esimerkkejä
preceden\printf.c - muotoiluformaatit
#include <stdio.h>
int main(void)
{
char s[10]="Kissa"; int i=175; double d=1.75;
printf(" 123456789012345678901234567890123456789012345678901234567890\n");
printf("1 |%s|%d|%lf|\n",s,i,d);
printf("2 |%10s|%10d|%10.5lf|\n",s,i,d);
printf("3 |%- 10s|%- 10d|%- 10.5lf|\n",s,i,d);
printf("4 |%10p|%10x|%lg|\n",s,i,d);
printf("5 |%010s|%10X|%le|\n",s,i,d);
printf("6 |%- 10.2s|%+10d|%+4.1lE|\n",s,i,d);
printf("7 |%10.2s|%+010d|%1.0lg|\n",s,i,d);
printf("8 |%*.*s|%+0*d|%*.0lg|\n",10,2,s,10,i,1,d);
return 0;
}
123456789012345678901234567890123456789012345678901234567890
1 |Kissa|175|1.750000|
2 | Kissa| 175| 1.75000|
3 |Kissa |175 |1.75000 |
4 | FFEC| af|1.75|
5 | Kissa| AF|1.750000e+00|
6 |Ki | +175|+1.8E+00|
7 | Ki|+000000175|2|
8 | Ki|+000000175|2|