I'm developing a mod for Quake2. When the level is changed, some stats are cleared and some are written to save game file.

My mod has a level system that affects the power of weapons, etc things.

But, then i encountered a problem. I want to save my character data to a file and then read it to restore the values on level change.

A Friend of mine said that i should use fwrite for writing the data.

fwrite (&ent->client->pers.lvl, sizeof(int), 1, fp);
fwrite(&ent->client->pers.exp, sizeof(int), 1, fp); 
fwrite(&ent->client->pers.money, sizeof(int), 1, fp);

But i dont have any idea how the read the data..I know the place where to read the data though.. So I'm requesting help on reading binary data.

(Also i dont know if i did something wrong in fwrite so someone can say a word or two about them for me)

Any help is welcome :)

Recommended Answers

All 4 Replies

There's a corresponding direct input function called fread.

Any examples?

Also how can i read the level, exp and money variables from binary file?

>Any examples?
Click me!

>Also how can i read the level, exp and money variables from binary file?
Whoa, deja vu! To read a file you use the inverse of how you wrote the file. So instead of fwrite, use fread. Didn't I already say that?

Okay, Thank you :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.