|
-
October 2nd, 2002, 08:56 PM
#1
have problem using C programming in writing data into a text file!
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,
gechin
-
October 2nd, 2002, 09:09 PM
#2
after looking at my posting, i found that the data was not display like what i type in the first place.so i have to explain a litter bit more so that you all will know what exactly i'm trying to say.
i want my data to arrange in 5 colums. example for 3th colum:
_______________
salary
100
10
300
900
1200
_________________
and the 4th colum
_________________
O.T
100
20
400
200
_________________
but some of the data did not start at it own colums. this happend when the "float" value is more that hundred or even more.
i hope you all understand what am i trying to say here.
thankz again,
gechin
-
October 3rd, 2002, 05:07 AM
#3
Re: have problem using C programming in writing data into a text file!
Originally posted by gechin
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);
Well...I do not know it this will fix all of your problems since I took only a quick look but the above line should be...
Code:
fprintf(filename,"%d\t%c%c%c\t%0.2f\t%0.2f\t%0.2f",bil,name[0],name[1],name[2],salary,ot,total);
Last edited by Andreas Masur; October 3rd, 2002 at 04:06 PM.
-
October 3rd, 2002, 03:52 PM
#4
A common mistake when looking at tab-delimited files is tab settings. If you are looking at your file in a text editor that has the tabs set to every 8 characters, for example, then putting a value that's 8 characters long will cause the remaining values in the row to be right-shifted by one column.
If you're not sure, try opening it up in Excel or change your tab settings to be really big.
-
October 8th, 2002, 11:46 PM
#5
well thank for the solution that you all give. i have found a more simple way to solve it. That is:
fprintf(filename,"%d \t%c%c%c \t8.2%f \t8.2%f \t8.2%f",bil,name[0],name[1],name[2],salary,ot,total);
that is replace the 0 with an integer such as 8. this will allocate 8 space for us to fill in our value.
thanks,
gechin
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|