Page 2 of 2

Re: fwrite problem

PostPosted: Thu Sep 16, 2010 1:40 pm
by tzoli
Hi.
Again a problem...
How can i write numbers in the file? :?:
My fwrite code always freeze the GE.
Code: Select all
int penz = money.textNumber;
FILE *f = fopen("s1m.txt", "r+");
fprintf(f,"%d,",&penz);
fclose(f);


This code is good but if Money = 0 in the file wrote:
Code: Select all
16253000

Re: fwrite problem

PostPosted: Thu Sep 16, 2010 2:08 pm
by Bee-Ant
tzoli wrote:
Code: Select all
[b]int[/b] penz = money.textNumber;
FILE *f = fopen("s1m.txt", "r+");
fprintf(f,"[b]%d[/b],",&penz);
fclose(f);

Take a look on the bolds...
if you use int, you should use %i
And I think you don't need to put & on fprintf...
So, the correct code may be:
Code: Select all
int penz = money.textNumber;
FILE *f = fopen("s1m.txt", "r+");
fprintf(f,"%i,",penz);
fclose(f);

Also, be careful of textNumber...
It's not really a number. Try to avoid getting number from it

Re: fwrite problem

PostPosted: Thu Sep 16, 2010 2:28 pm
by tzoli
Thanks.
Image