fwrite problem

Non-platform specific questions.

Re: fwrite problem

Postby tzoli » Thu Sep 16, 2010 1:40 pm

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
Creepers are capable of climbing ladders, despite lacking arms. (Minecraft wiki)
User avatar
tzoli
 
Posts: 343
Joined: Sat Jun 12, 2010 6:54 pm
Location: Behind you
Score: 15 Give a positive score

Re: fwrite problem

Postby Bee-Ant » Thu Sep 16, 2010 2:08 pm

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
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: fwrite problem

Postby tzoli » Thu Sep 16, 2010 2:28 pm

Thanks.
Image
Creepers are capable of climbing ladders, despite lacking arms. (Minecraft wiki)
User avatar
tzoli
 
Posts: 343
Joined: Sat Jun 12, 2010 6:54 pm
Location: Behind you
Score: 15 Give a positive score

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest