Solved

Left/Right justify ?

Posted on 2001-08-11
6
494 Views
Last Modified: 2010-04-15
printf("%5d %20s %2c %8s %10s %10s %10s\n", test1, test2, test3....);

Above printf statement will print right justify. How do I make it left justify ?
0
Comment
Question by:weiyee08
  • 2
  • 2
  • 2
6 Comments
 
LVL 1

Accepted Solution

by:
roaknog earned 45 total points
ID: 6375394
#include <stdio.h>
void main(){
printf("\nright\n%10c\t%5i\%20x",'z',2,13);
printf("\nleft\n%-10c\t%-5i\%-20x",'z',2,13);
}
0
 
LVL 1

Expert Comment

by:roaknog
ID: 6375396
//you did not need the \t in my answer
// to left justify you use the - flag after the %
#include <stdio.h>
void main(){
printf("\nright\n%10c%5i\%20x",'z',2,13);
printf("\nleft\n%-10c%-5i\%-20x",'z',2,13);
}
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 6376312
use minus signs
printf("[%5d][%20s][%9d][%8s]", 1, "this", 14, "that");

printf("[%-5d][%-20s][%-9d][%-8s]", 1, "this", 14, "that");
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 6

Expert Comment

by:Triskelion
ID: 6801839
Um...
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6801962
No response here, will be force accepting later today to close.

Moondancer
Community Support Moderator @ Experts Exchange
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6802000
Recommendation from this applied and finalized today.
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20266763
Moondancer
Community Support Moderator
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to declare a 2-dimensional version of strlen 4 201
How to create project in Eclipse ? 1 193
XCode crashes while uploading to app store. 5 257
Problem to scan all sheets 3 95
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…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

896 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

12 Experts available now in Live!

Get 1:1 Help Now