By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,190 Members | 1,653 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,190 IT Pros & Developers. It's quick & easy.

print unsigned long long right justified

P: n/a
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.

Jul 3 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On Jul 3, 7:11 pm, trbosjek <ivan.petrov...@t-mobile.hrwrote:
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.

Jul 3 '07 #2

P: n/a
trbosjek wrote:
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);
Jul 3 '07 #3

P: n/a
Sharath <av*******@gmail.comwrote:
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. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Jul 3 '07 #4

P: n/a
Christopher Benson-Manica <at***@faeroes.freeshell.orgwrote:
"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.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Jul 3 '07 #5

P: n/a
On Jul 3, 7:41 pm, Christopher Benson-Manica
<a...@faeroes.freeshell.orgwrote:
Sharath <avshar...@gmail.comwrote:
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.
My apologies for wrongly stating that. I should have looked into the
standard prior to posting that.

Jul 3 '07 #6

P: n/a

"Sharath" <av*******@gmail.comha scritto nel messaggio news:11*********************@a26g2000pre.googlegro ups.com...
On Jul 3, 7:11 pm, trbosjek <ivan.petrov...@t-mobile.hrwrote:
>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.
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.
Jul 3 '07 #7

P: n/a
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..

Jul 3 '07 #8

P: n/a
Sharath wrote:
On Jul 3, 7:11 pm, trbosjek <ivan.petrov...@t-mobile.hrwrote:
>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.
Nonsense. Just read the standard on printf.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jul 3 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.