April 15, 2021, 03:07:41 AM

Author Topic: having problem in writing data into a text file  (Read 6455 times)

0 Members and 1 Guest are viewing this topic.

mch

  • Guest
having problem in writing data into a text file
« on: October 03, 2002, 12:27:31 AM »
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

Offline wilnix

  • mv user /dev/null
  • Administrator
  • Forum Hero
  • *****
  • Posts: 690
  • Country:
  • Gender: Male
  • You're not the fastest packet in the subnet...
    • Wilnix - The NetAdmin's Resource
Re:having problem in writing data into a text file
« Reply #1 on: October 16, 2002, 11:45:36 AM »
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
alt email address: wilnix@hackphreak.org