Solved

How to use printf for this special format

Posted on 2006-11-13
5
233 Views
Last Modified: 2010-04-15
Hi I want to print something like this
name1   1704   5678
nam2       121      78


printf("??",name1","121","5678")
printf("??",nam2","121","78")
What need to put in the ?? to achieve this format?
0
Comment
Question by:william007
  • 2
  • 2
5 Comments
 
LVL 16

Assisted Solution

by:PaulCaswell
PaulCaswell earned 200 total points
ID: 17934797
Hi william007,

Are you thinking of something like:

printf ( "%8.8s\t%4.4d\t%4.4d\n", "name1", 1704, 5678);

Paul
0
 
LVL 84

Accepted Solution

by:
ozo earned 300 total points
ID: 17934837
I think you mean
printf ( "%-8s\t%4d\t%4d\n", "name1", 121, 78);
0
 
LVL 9

Author Comment

by:william007
ID: 17935482
Hi, for -8 means left align with fix 8 letter, if not enough then pad with space.
But what does 8.8,4.4 in PaulCaswell post means?
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 300 total points
ID: 17935593
%8.4s would print no more than 4 characters of "name1"
%8.4d would pad the number with 0s up to 4 digit, then with spaces up to 8 characters
0
 
LVL 9

Author Comment

by:william007
ID: 17970880
Thanks=)
0

Featured Post

Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now