473,408 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

print unsigned long long right justified

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
8 4230
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
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
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
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
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

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: William Payne | last post by:
Hello, I have a variable of type unsigned long. It has a number of bits set (with set I mean they equal one). I need to determine those bits and their position and create new numbers from them. For...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
14
by: moumita | last post by:
Hi All, I need to convert 4 bytes to an unsigned long. Suppose I have one array like unsigned char buf.I need to convert these 4 bytes into a single unsigned long. Is the following piece of code...
16
by: Wade Ward | last post by:
/* C version */ static unsigned long t,x=123456789,y=362436069,z=21288629,w=14921776,c=0; unsigned long KISS(){ x+=545925293; y^=(y<<13); y^=(y>>17); y^=(y<<5); t=z+w+c; z=w; c=(t>>31);...
3
by: beagle197 | last post by:
Folks, What is a good way to print a standard 80 (or less) column of text where the left side being a field name text, and right side being the space padded value? e.g....
2
by: laurent.pauloin | last post by:
Hello I have a buffer of char and I want to print in a 64 bit word in hexa. charbuff0 charbuff1 charbuff2 charbuff3 charbuff4 charbuff5 charbuff6 charbuff7 64bit msb 64bit lsb
105
by: Keith Thompson | last post by:
pereges <Broli00@gmail.comwrites: These types already have perfectly good names already. Why give them new ones? If you must rename them for some reason, use typedefs, not macros. --
3
by: Cameron Simpson | last post by:
On 18Aug2008 11:58, Beema Shafreen <beema.shafreen@gmail.comwrote: | In my script i have to print a series of string , so | | print "%s\t%s\t%s\t%s\t%s\t%s\t" %("a","v","t","R","s","f") | | I...
21
by: arnuld | last post by:
I have created a program to print the input words on stdout. Input is taken dynamically from stdin. In each word, each input character is allocated dynamically. I have ran this program with a file...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.