Re: Printf puzzlement
- Posted by ChrisB (moderator) Dec 28, 2018
- 847 views
Hi, another way
printf(1, "%7.7s", {string})
will print the string into an allocation of 7 spaces, clipped to a maximum of 7 characters, so
1234567
printf(1, "%7.3s", {string})
123
and printf(1, "%-7.3s", {string})
123
the '-' sign says to justify to the left, and the number after the decimal point says how many characters to print within the allocated space. The allocated space can be overflowed, so just watch for that.
Cheers
Chris
Sorry, just noted that that justification didn't show properly
printf(1, "%7.7s", {string}) will print the string into an allocation of 7 spaces, clipped to a maximum of 7 characters, so 1234567 printf(1, "%7.3s", {string}) 123 and printf(1, "%-7.3s", {string}) 123