Solved

Left/Right justify ?

Posted on 2001-08-11
6
497 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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 while-loops in the C programming language.

840 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