right justifiied

This is a discussion on right justifiied within the C Programming forums, part of the General Programming Boards category; how do I align my figures so the column appers to be right justified i have several lines....

  1. #1

    right justifiied

    how do I align my figures so the column appers to be right justified

    i have several lines.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe

    printf( "%5d", 123 );
    printf( "%5d", 12345 );

  3. #3
    train spotter
    Join Date
    Aug 2001
    near a computer
    int iWidth=COLUMN_WIDTH;


    the * is taken as the width of the cell. Works with printf() ect.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Don't you just hate people that post the same thing over and over again and don't bother reading the reply to it?

    Hope is the first step on the road to disappointment.

  5. #5
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    It is important to specify the size of the fields.

    fprintf(fptr,"%2d%20s%8.2lf",num," ", float_num);

    I have recently discovered the utility of specifying the field sizes because I recently used datafiles like this. Cprogramming borad screwed this up, the name fields should be the same length but this boards formatting ****ed it.

    4902348093esome name94023942304809348204
    40982304984another 42392904832094832049
    40394803240yet more 40934223048320940393

    This file can be used by more than one program. In order to skip pieces of data that you do not want to read use the star.

    fprintf(fptr,"%*2c,%3d", num);

    In this code the star allows the first two characters to be skipped.

Popular pages Recent additions subscribe to a feed

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