Thread: Left Justified (sorry)

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    19

    Left Justified (sorry)

    How who I have my printf statement to have the numbers come out like thisn (no stars these should be spaces)

    *** 10
    *** 50
    *** 250
    *** 650
    *** 1250

    Thanks!!

    This is what I have
    printf("%d\n", k);

    10
    50
    250
    650
    1250
    Last edited by Frank_Rye; 10-28-2005 at 02:48 PM.

  2. #2
    Registered User
    Join Date
    Oct 2005
    Posts
    19
    grr no its not coming out like I put it I must be to the left not right side

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    I have no idea what you want, so if the following example doesn't help, please be more specific and use code tags to preserve formatting:
    Code:
    #include <stdio.h>
    
    #define length(a) ( sizeof (a) / sizeof *(a) )
    
    int main ( void )
    {
      int a[] = {1,10,100,1000};
      int i;
    
      for ( i = 0; i < length ( a ); i++ )
        printf ( "%-5d***\n", a[i] );
      puts ( "" );
    
      for ( i = 0; i < length ( a ); i++ )
        printf ( "%5d***\n", a[i] );
      puts ( "" );
    
      for ( i = 0; i < length ( a ); i++ )
        printf ( "***%5d\n", a[i] );
      puts ( "" );
    
      for ( i = 0; i < length ( a ); i++ )
        printf ( "***%-5d\n", a[i] );
    
      return 0;
    }
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to convert to left justified bits?
    By Subsonics in forum C Programming
    Replies: 18
    Last Post: 02-18-2009, 07:16 PM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Please help me
    By teedee46 in forum C++ Programming
    Replies: 9
    Last Post: 05-06-2002, 11:28 PM