Thread: right justifiied

  1. #1
    Unregistered
    Guest

    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
    Location
    The edge of the known universe
    Posts
    39,656
    Try

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

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Or
    int iWidth=COLUMN_WIDTH;

    sprintf(sBuffer,"%*d",iWidth,iValue);

    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
    Posts
    14,826
    Don't you just hate people that post the same thing over and over again and don't bother reading the reply to it?

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    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