fwrite(size_t_count)
Hi,
can any one tell me what size_t_count does, i couldnt get it .
thanks guyz !
fwrite(const void*_str,size_t_Size,size_t_count,file *_File);
rowly
Junior Poster in Training
65 posts since Sep 2006
Reputation Points: 10
Solved Threads: 3
aha beautifull ! now i got it ! :)
1 more question !
strcpy(rcust[i].item, strtok(NULL,","));
i used the strtok to read untill i reach a comma...
how can i replace the comma by a ";" ?
for example i want to do the same thing but now i want to write it to another file and replace the , by a semi colon ?!
have any idea how to do that with strtok or another function ?!
thx champ
rowly
Junior Poster in Training
65 posts since Sep 2006
Reputation Points: 10
Solved Threads: 3
use strchr() to find the comma then replace it
char str[] = "Hello,World";
// find the comma
char *ptr = strchr(str,',')
// replace it if found
if(ptr != NULL)
*ptr = ';';
Now, put the above in a loop to find and replace all the commas in the string.
Ancient Dragon
Retired & Loving It
30,040 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
aha !
if i want to write to a file, do i have to fread it first or just
fwrite it straight away ?
thx champ
rowly
Junior Poster in Training
65 posts since Sep 2006
Reputation Points: 10
Solved Threads: 3
if i want to write to a file, do i have to fread it first or just
fwrite it straight away ?
It's tricky. Can you post some code that shows what you're trying to do?
Inanna
Junior Poster in Training
90 posts since Oct 2006
Reputation Points: 53
Solved Threads: 6
aha !
if i want to write to a file, do i have to fread it first or just
fwrite it straight away ?
thx champ
of course the program has to read it -- how else do you think it is going to be able to know where the commans are and what to write to the new file?
for each line in the source file
read a line
replace all commas with semicolons
write the string to the new file
end
Ancient Dragon
Retired & Loving It
30,040 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
Actually, you read from one file, then write to another file. You don't want to read and write to the same file. It gets too complicated.
WaltP
Posting Sage w/ dash of thyme
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943
Actually, you read from one file, then write to another file. You don't want to read and write to the same file. It gets too complicated.
I did not suggest he write to the same file that he's reading. read the sudo-code again please -- "write tonew file"
Ancient Dragon
Retired & Loving It
30,040 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
I did not suggest he write to the same file that he's reading. read the sudo-code again please -- "write to new file"
Actually Mr. WaltP did not direct his comment to you.
If you will read the OP recent post:if i want to write to a file, do i have to fread it first or just
fwrite it straight away ?
Mr. WaltP's comment I think is directed to the OP.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
Actually Mr. WaltP did not direct his comment to you.
True. Thank you Mr. SOS for clearing that up in my absense. :)
WaltP
Posting Sage w/ dash of thyme
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943
Heheh :] wts happening here :)
wel
for each line in the source file
read a line <----------------------------- thats easy !
replace all commas with semicolons <--------- i'll try my best
write the string to the new file <------------- kinda of problem in here coz i have some int arrays example:
int cust_num;
char item[50];
int cost;
its easy to use fputs for the char item[50] but still struggling with int cust_num (conversion) i'll appreciate any help !
example:
fputs(rSales[i].cust_num,fpr);
1 more thing i tried to write rSales[i].cust_num using
fputc(rSales[i].cust_num,fpr);
but the problem that i'm getting some ASCII codes in fpr
end<------------Thx for help guyz
rowly
Junior Poster in Training
65 posts since Sep 2006
Reputation Points: 10
Solved Threads: 3
Convert cust_num to string for example with sprintf.
char buff[MAX];
sprintf(buff, "%d", cust_num);
fputs(buff, fpr);
/* and for fputc */
fputc(cust_num + '0', fpr); /* suposing that cust_num is less than 10 and smalles 0 */
oi its WorkSSS :cheesy:
i have kinda of phobia from conversion ! do u know any good site for conversions !
thx mate :!:
rowly
Junior Poster in Training
65 posts since Sep 2006
Reputation Points: 10
Solved Threads: 3
you don't really need sprintf at all. just use fprintf()
int cust_num = 123;
fprintf(fpr, "%d\n", cust_num);
// now if you want the number to have at least 5 digits, with leading 0s when needed
fprintf(fpr, "%05d\n", cust_num);
Ancient Dragon
Retired & Loving It
30,040 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
that works fine mate !
any website about conversions ! i better get some knowledge !
cheers Champ
rowly
Junior Poster in Training
65 posts since Sep 2006
Reputation Points: 10
Solved Threads: 3
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
its easy to use fputs for the char item[50] but still struggling with int cust_num (conversion) i'll appreciate any help !
Where did this conversion come in? I thought you were reading each line and replacing , with ;. There should be no conversions anywhere.
WaltP
Posting Sage w/ dash of thyme
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943
Where did this conversion come in? I thought you were reading each line and replacing , with ;. There should be no conversions anywhere.
wel waltP, i'm doing two programs in the 1st one i have to read from a csv file and eliminate the ","
s1.csv contents:2,Ajle,1999999,235.6,6
3,ksiSeal,1062230,222.8,2
...
...
...
the second program is reading from the same file s1.csv and and write it to a new *.txt file with replacing the delimiter "," with a delimiter ";" and by doin some ascending sort....
example *.txt contents:
2;Ajle;1999999;235.6;6
3;ksiSeal;1062230;222.8;2
...
...
...
and we have a fix struct in both programs :) so thats why i was doin conversion !
Anyways i'm bout to finish it all still have the sort part and bang finish ! :)
thx alote guyz
rowly
Junior Poster in Training
65 posts since Sep 2006
Reputation Points: 10
Solved Threads: 3
sorry bout na postin the programs , i'm uni student and for sure i'll get a good circle if somebody copy It.
DANIWEB is wide opened on google and yahoo ! :p so everyone in ma class will have the same code ! hahah
cheers mate !
:]
rowly
Junior Poster in Training
65 posts since Sep 2006
Reputation Points: 10
Solved Threads: 3