print unsigned long long right justified

T

trbosjek

A total newbie. This simple example below prints left justified. How
do I make it right justified, as a number should be? It works for
smaller integers (other than unsigned long long).
#include <stdio.h>
int main ()
{
unsigned long long int bigger, smaller;

bigger= 18446744073709551615ULL;
smaller=4294967296ULL;

printf( "%llu\n", bigger);
printf( "%llu\n", smaller);
}

Compiled with gcc on HPUX.
 
S

Sharath

A total newbie. This simple example below prints left justified. How
do I make it right justified, as a number should be?

There is no such thing as left justified or right justified in C
language, what you give in printf will be just printed in the standard
output device, and that need not always be a monitor. Your compiler
may provide some libraries to move the cursor and then print at
desired location, but that is off-topic here. Ask in a newsgroup that
discusses your compiler.
 
S

Spoon

trbosjek said:
A total newbie. This simple example below prints left justified. How
do I make it right justified, as a number should be? It works for
smaller integers (other than unsigned long long).
#include <stdio.h>
int main ()
{
unsigned long long int bigger, smaller;

bigger= 18446744073709551615ULL;
smaller=4294967296ULL;

printf( "%llu\n", bigger);
printf( "%llu\n", smaller); return 0;
}

You could specify a field width.

printf("%20llu\n", smaller);
 
C

Christopher Benson-Manica

Sharath said:
There is no such thing as left justified or right justified in C
language

That is not true. n869 goes so far as to describe the '-' flag
character, which may appear after the '%' character in a *printf
conversion specifier, thus (7.19.6.1, p6):

"The result of the conversion is left-justified within the field. (It
is right-justified if this flag is not specified."

You might want to check the standard before your next post.
 
C

Christopher Benson-Manica

Christopher Benson-Manica said:
"The result of the conversion is left-justified within the field. (It
is right-justified if this flag is not specified."
^ ), obviously.
My apologies to the standard for misquoting it.
 
S

Sharath

That is not true. n869 goes so far as to describe the '-' flag
character, which may appear after the '%' character in a *printf
conversion specifier, thus (7.19.6.1, p6):

"The result of the conversion is left-justified within the field. (It
is right-justified if this flag is not specified."

You might want to check the standard before your next post.

My apologies for wrongly stating that. I should have looked into the
standard prior to posting that.
 
A

Army1987

Sharath said:
There is no such thing as left justified or right justified in C
language, what you give in printf will be just printed in the standard
output device, and that need not always be a monitor. Your compiler
may provide some libraries to move the cursor and then print at
desired location, but that is off-topic here. Ask in a newsgroup that
discusses your compiler.
What?
" 123" is a right-justified number in a 8-character field.
"123 " is a left-justified number in a 8-character field.

Look up the '-' flag in a fprintf conversion specification.
 
T

trbosjek

You could specify a field width.
printf("%20llu\n", smaller);

Thank you so much Spoon! This works. I guess I thought this "ll" from
"llu" stood for some kind of a default width..
 
C

CBFalconer

Sharath said:
There is no such thing as left justified or right justified in C
language, what you give in printf will be just printed in the
standard output device, and that need not always be a monitor.
Your compiler may provide some libraries to move the cursor and
then print at desired location, but that is off-topic here. Ask
in a newsgroup that discusses your compiler.

Nonsense. Just read the standard on printf.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top