Find the answer to your Linux question:
Results 1 to 9 of 9
Hey guys, I want to print out something similar to the following in evenly spaced columns. But I don't know to how to. I've tried to do it, but its ...
  1. #1
    Just Joined!
    Join Date
    Sep 2007
    Posts
    13

    Printing out data in evenly spaced columns

    Hey guys, I want to print out something similar to the following in evenly spaced columns. But I don't know to how to. I've tried to do it, but its not how I want it to be printed out. This info is read from a data file.

    Square Root sqrt 10
    Exponential Function exp 10
    Natural Logarithm log 10
    Logarithm log10 10
    Absolute Value fabs 10

    and so on... The second row is suppose to be straight, I know its a little slightly not straight.

    But I do not know how to print out so that the second is all evenly matched and spaced out.

    This is what I have so far..
    for (i = 0; i < num; i ++)
    {
    printf("%s %5s %10d", name, function, number);
    }

    I thought that it would be something similiar to this, but it doesn't work. Does anyone have any other way to doing this in Linux. Thanks.

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    When does your professor or instructor say this assignment is due?

  3. #3
    Just Joined!
    Join Date
    Sep 2007
    Posts
    13
    Square Root sqrt 10
    Exponential Function exp 10
    Natural Logarithm log 10
    Logarithm log10 10
    Absolute Value fabs 10

    It is suppose to look like that, I didn't realize it printed out wrong.

  4. #4
    Just Joined!
    Join Date
    Sep 2007
    Posts
    13
    It still won't print out the way I want it to .. But the starting from sqrt 10 and exp , log, fabs 10, it suppose to be in a separate column spaced out from the Square Root section.

  5. #5
    Just Joined!
    Join Date
    Sep 2007
    Posts
    13
    Exponent__________Exp
    Logarithm__________Log
    Natural Log_________Log
    Absolute Value______Abs

    Kind of like this.. But without the lines

  6. #6
    Just Joined! vigour's Avatar
    Join Date
    Oct 2007
    Posts
    68
    Quote Originally Posted by devilsangels287 View Post
    Exponent__________Exp
    Logarithm__________Log
    Natural Log_________Log
    Absolute Value______Abs

    Kind of like this.. But without the lines
    Can't you just use TABs between the columns? Like 2 or 3 tabs?

  7. #7
    Just Joined!
    Join Date
    Sep 2007
    Posts
    13
    I would but the thing is the data is read from a data file and the words in the first column are all different lengths and then some of the words in the second column are also all different lengths.

  8. #8
    Just Joined! vigour's Avatar
    Join Date
    Oct 2007
    Posts
    68
    Well.. if you put for an example 3 or 4 tabs between columns, fields length shouldn't be a problem. Except of course you don't have a whole sentence as a filed value. How long may the longest value be?

  9. #9
    Just Joined!
    Join Date
    Sep 2007
    Posts
    13
    Well some of the lines are a lot longer than the others, such as one may be as long as

    if you put for an example 3 or 4 tabs between__________COLUMN
    if you put for an___________________________________COLUMN
    if you put for an example 3 or 4______________________COLUMN
    if you put for_____________________________________COLUMN

    and I want print them using one print statement in a loop.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...