Solved

How to use printf for this special format

Posted on 2006-11-13
5
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
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.

630 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