-
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?
-
Any way we can get this attachment on the FAQ board for reference to everyone else that asks this question?
-
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?
-
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.