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);

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);

It means how many of size_t_Size you want to write. fwrite(buff, sizeof(int), 4, someFile) means you want to write four ints to file.

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

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.

aha !
if i want to write to a file, do i have to fread it first or just
fwrite it straight away ?
thx champ

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?

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

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.

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 to new file"

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.

Actually Mr. WaltP did not direct his comment to you.

True. Thank you Mr. SOS for clearing that up in my absense. :)

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.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

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 */

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 :!:

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);

that works fine mate !
any website about conversions ! i better get some knowledge !
cheers Champ

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.

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

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 !
:]

This question has already been answered. Start a new discussion instead.