fwrite problem

Non-platform specific questions.

fwrite problem

Postby tzoli » Wed Aug 04, 2010 4:49 pm

I have a problem with fwrite.
This is my code:
Code: Select all
unsigned px = 0;
FILE *f = fopen("C:/ct.txt","r+");
fwrite(&px,"x",10,f);
fclose(f);

And the error:
Incompatible types:Cannot convert from "const * char" to "unsigned"
What can i do for fix it?
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 savvy » Wed Aug 04, 2010 5:49 pm

it means there something in there which isnt supposed to be, or that your missing a peice of info which seperates them, OR even that you have something splitting up something thats supposed to be together, but im not sure what. try rethinking the code from the start.
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: fwrite problem

Postby Game A Gogo » Wed Aug 04, 2010 5:51 pm

Actually, this just means you placed a variable that is a const*char (Constant string, a variable you declared that is a string) where an unsigned (An integer without negative values, I beleive...) should go
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: fwrite problem

Postby Game A Gogo » Wed Aug 04, 2010 5:53 pm

it would also be easier to help you, if you told us where this error happens (On which line? it always tells you thankfully!)
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: fwrite problem

Postby Fuzzy » Wed Aug 04, 2010 6:01 pm

What immediately stands out to me is that you used the wrong slash for windows and you should have escaped it.

FILE *f = fopen("C:\\ct.txt","r+");

Also, I wouldnt write to the root C folder like that. Put it in with your game.

FILE *f = fopen("C:\\somegame\\ct.txt","r+");
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: fwrite problem

Postby tzoli » Wed Aug 04, 2010 6:02 pm

Thanks.
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 tzoli » Wed Aug 04, 2010 6:24 pm

I have problem again :twisted:
Code: Select all
int px = 0;
FILE * f = fopen("C:\\ct.txt","w");
fwrite(&px,1,1,f);
fclose(f);

Aren't errors but not write the file... :(
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 makslane » Wed Aug 04, 2010 7:47 pm

You can create files only inside the game folder.
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Re: fwrite problem

Postby asmodeus » Wed Aug 04, 2010 8:03 pm

makslane wrote:You can create files only inside the game folder.

Why that? I don't understand it.
User avatar
asmodeus
 
Posts: 483
Joined: Thu Oct 11, 2007 5:04 pm
Location: Germany
Score: 43 Give a positive score

Re: fwrite problem

Postby makslane » Wed Aug 04, 2010 8:45 pm

Security.
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Re: fwrite problem

Postby asmodeus » Wed Aug 04, 2010 9:27 pm

makslane wrote:Security.

Okay, I see...
But you could make have possible to access files in sub directories, e.g. files from a "data" dir, being in the same dir as the game. Just not allowing for example "../" or "C:/".
User avatar
asmodeus
 
Posts: 483
Joined: Thu Oct 11, 2007 5:04 pm
Location: Germany
Score: 43 Give a positive score

Re: fwrite problem

Postby tzoli » Thu Aug 05, 2010 5:35 am

Okay...But can how can I write to file strings?
My codes doesn't running corectly. :(
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 tzoli » Mon Aug 09, 2010 7:02 am

I have a problem whit my code:
Code: Select all
int px = 100;
FILE *f = fopen("ct.txt", "r+");
fwrite(&px, ymouse, sizeof(px), f);
fclose(f);

No errors but in the file wrote:
d `Ě €°g €°g  °g €ăÇ €°g €°g  °g °Č  €°g  °g Xnż s ˙˙˙˙ €ăÇ H ř H ř L ř č‹Â řÔÉ ¬ż ¬ż čě ŕsż ąĆ ŕĘÉ čüĂ 0şŔ °cĚ đ/É đż ČoČ
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 » Mon Aug 09, 2010 10:02 am

fwrite() would write text in binary code, if you want it to be "readable" use fprintf() instead.
Code: Select all
fprintf(f,"%d,",&ymouse);
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 » Mon Aug 09, 2010 1:44 pm

Thanks!It's run correctly :D
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

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest