hello everybody! i have a problem using C in writing data into a text file.
actually i can writen the data into the text file already by using the code:
___________________________________________
fprintf(filename,"bil \tname \tsalary \tO.T \t total");
while(!EOF)
fprintf(filename,"%d \t%c%c%c \t0.2%f \t0.2%f \t0.2%f",bil,name[0],name[1],name[2],salary,ot,total);
_________________________________________________
the problem i facing is the data was not properly arrange. for example:
bil name salary O.T total
1 mch 10.00 10.00 20.00
2 efg 20.00 20.00 40.00
3 jkl 100.00 100.00 200.00
4 opq 400.00 100.00 300.00
the problem occur when the value of salary, O.T and total is more than hundred and even thousand. what code must i write in order to get this result ???:
bil name salary O.T total
1 mch 10.00 10.00 20.00
2 efg 20.00 20.00 40.00
3 jkl 100.00 100.00 200.00
4 opq 400.00 100.00 300.00
5 mnb 1000.00 500.00 1500.00
which is nice and easy to read.
thankz,
mch
mch -
What you might need to do is use the precision field or the width field to format with. This will align each var width a certain amount of padding and decimal places. Some help can be found at:
http://www.thinkage.ca/english/gcos/expl/nsc/lib/printf.html
Let me know if that helps or not.
~wilnix