Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to use printf for this special format

Posted on 2006-11-13
5
Medium Priority
?
260 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 800 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 85

Accepted Solution

by:
ozo earned 1200 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 85

Assisted Solution

by:ozo
ozo earned 1200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

972 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