Solved

Left/Right justify ?

Posted on 2001-08-11
6
498 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
Technology Partners: 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!

 
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

Technology Partners: 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

Suggested Solutions

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…
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…
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.

733 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