Width, Precision, Flags
Control formatting.
Controlling Output Width
A number after % sets the minimum field width. The value is right-aligned and padded with spaces.
#include <stdio.h>
int main(void) {
printf("[%5d]\n", 42);
return 0;
}Left Alignment
A - flag left-aligns the value within the field.
#include <stdio.h>
int main(void) {
printf("[%-5d]\n", 42);
return 0;
}All lessons in this course
- printf Format Specifiers
- scanf and Input
- Width, Precision, Flags
- Common I/O Pitfalls