How do I append blank spaces to the end of a string using printf
?
I can't find any examples where spaces are appended to the right. A similar question I found use printf
to add spaces to the left of the string instead.
Use negative numbers to left-align (i.e. "pad" to the right).
#include <stdio.h>
int main() {
const char *s = "hello";
printf("%30sworld\n", s);
printf("%-30sworld\n", s);
}
This prints
helloworld
hello world
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With