Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to use printf for this special format

Posted on 2006-11-13
5
Medium Priority
?
255 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 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 84

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 84

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

Independent Software Vendors: 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

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 and use structures in the C programming language.

722 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