File I/O Manipulation
I am writing data to *.dat file in columns. How can I manipulate the output so every number in the first column is 6 characters wide and the second column is 5 characters wide? In C++, I used setw(6) to set the width of each output. How can I do this in C?
This didn't work.
fprintf(outfile, "%03.2lf %2.2lf", data1[i], data2[i]);
I try to use strncpy to acquire the second column's data. Since the first column has different widths, based on the number, I index at the wrong position.
Basically I need to read ascii data into the program.
Saying something "didn't work" really doesn't tell us what about it you didn't like other than that it obviously didn't fit whatever you're trying to achieve.
What does this do for you?
fprintf(outfile, "%06.2lf %05.2lf", data1[i], data2[i]);
Change the %3 to a %6, and the %2 to %5, that's your width of field settings. I have never seen an "lf" data designation for printf. Try just "f'.
width of 8 for double?
This seems to work when I output double's
and this does not
Does the width need to be 8 for outputing a double?
My guess is that you're not taking the decimal point into account. ;)
And what does it mean? "not work" is not good enough explanation of the problem...
It cannot be compiled?
It crashes during run?
It outputs the values in a way a don't expect?
post expected output and the actual output for the first and the second sample of the code...