printing data to a file

This is a discussion on printing data to a file within the C Programming forums, part of the General Programming Boards category; I am printing data with the type float to a file. My problem is the data needs to line up ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    6

    printing data to a file

    I am printing data with the type float to a file. My problem is the data needs to line up in nice neat columns and it isn't. Plus some of it is printing out in integer form (ex: 9.00 is printing out as 9).

    Please see the attached text file to see what the output looks like.

    Here is my fprintf statement for printing out the data. This is inside a loop to loop through the array of values.

    Code:
    fprintf(f," %g %g \n", value[i].num1, value[i].num2]);
    What can I do to make the data line up (left justified) in neat columns?
    Attached Files Attached Files

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Any way we can get this attachment on the FAQ board for reference to everyone else that asks this question?
    Attached Images Attached Images

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    6
    OK I solved the part of the lining up the columns.

    I still have the problem of some of the values printing out as integers. I really need to numbers to be a total of 7 characters wide.
    (EX: 47.0000 -.09876 1.09786)

    How can I fix it so they print out correctly?

  4. #4
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    It sort of depends on which digits you want to display. But I can imagine that all the solution begin by having a good look at sprintf.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  3. 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
  4. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 02:58 PM

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