1. Output string AS-is:
printf ("%s", str);
2. Output a string of the specified length, long without truncation, and right-justified when insufficient:
printf ("%ns", str); --n 10 binary values for the specified length
3. Output string of specified length, long without truncation, left justified when insufficient:
printf ("%-ns", str); --n 10 binary values for the specified length
4. Output a string of the specified length, truncated long, and right-justified when insufficient:
printf ("%n.ms", str); --n for the final string output length
--m is the length of the substring taken from the argument string
5. Output string of specified length, long truncation, left justified when insufficient:
printf ("%-n.ms", str); --n for the final string output length
--m is the length of the substring taken from the argument string
Note that the so-called super-long truncation of the M is not only a long time to play a role, but whether you are not long, you have to intercept so long. So
The output of printf ("%-5.2", "123") is:
12 Spaces Space Spaces
Only 2 characters are intercepted, others are filled with blanks, and left-justified.
6. The above n,m can be dynamically specified by substituting * instead of M or N, and then adding a numeric parameter to the parameter list. Example:
printf ("%-*.*s", 5, 2, "123"), as in the example above.
printf ("%*s", 5, "123"), indicates that the output length is 5, if the extra length is not truncated, enough words to fill, right to align.
Some formats for printf output strings