Solved

How to use printf for this special format

Posted on 2006-11-13
5
230 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

759 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

19 Experts available now in Live!

Get 1:1 Help Now