How do I right justify this?

This is a discussion on How do I right justify this? within the C Programming forums, part of the General Programming Boards category; I want to turn this... ********** ********* ******** ******* ****** ***** **** *** ** * into this... ********** ********* ******** ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    5

    How do I right justify this?

    I want to turn this...

    **********
    *********
    ********
    *******
    ******
    *****
    ****
    ***
    **
    *

    into this...
    **********
    *********
    ********
    *******
    ******
    *****
    ****
    ***
    **
    *

    Here's my code. Thanks.

    Code:
    #include <stdio.h>
    
    int main() {
    
    	int f, g;
    
    	for(f = 0; f < 10; f++) 
    	{
    		for(g = f; g < 10; g++) 
    		{
    			printf("*");
    		}
    		printf("\n");
    	}
        return 0;
    }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What have you tried?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    Omaha, Nebraska
    Posts
    116
    you could probably just try printing like you normaly would but with several tab escapes (\t)

    just my thoughts on it. hope it helps.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,756
    Logic dictates that you can pad with spaces, to align the *.
    Now I'll leave you to think of a solution to do just that.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    Or you can make use something like
    Code:
    printf("&#37;-100c", '*');

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. setw() - left justify
    By DJPG5 in forum C++ Programming
    Replies: 3
    Last Post: 02-06-2003, 05:46 PM
  2. how to right justify toolbar ??
    By Feras in forum Windows Programming
    Replies: 1
    Last Post: 12-06-2002, 03:36 PM
  3. left justify
    By Max in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2002, 06:32 PM
  4. right justify a text file
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2002, 12:17 AM
  5. Right justify?!?!
    By Claire in forum C++ Programming
    Replies: 6
    Last Post: 01-19-2002, 11:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21