Q:
Hi Peter,
I am a student at UCD and I was wondering how to right justify a line of
text output using the printf statement. I have three columns of data that
I need to justify. I'm using the built in Unix Compiler from the Mandrake
kernel. Thankx.
- *NAME-DELETED*
A:
Dear *NAME-DELETED*,
you can use the function printf. To right justify, you have to know to
what character position to jsutify the something you want to print. For
example:
printf("%80d",1);
prints the character 1 on the 80. position. The same is true for strings.
To left justify you have to use the - modifier, like
printf("%-80d",1);
which prints 1 and 79 spaces. Experience with this and type
man 3 printf
at the Mandrake command prompt to get the manual. "man printf" actually
does not work, because there is a printf command in the shell and that is
the default man page. You need the function.
Regards,
Peter
[ back to toc ]