Using File
Do you mean you're programming and you're trying to save, in which case what programming language are you using?
Otherwise......
If i'm creating a game, and I want to have a Save game option, I would like to:
1) Create a file
2) Save into the file data like Units X and Y
After I would like to add an Open game:
1)Open a file
2)Read data and convert it to the game
3)Position the units in the X and Y.
I hope someone can help me now...
First you have to declare a struct containing all the data you want - it could look like this:
code:typedef struct _Something{// Data goes here...} SOMETHING;
After the struct has been filled with the data you need, you can save it like this:
code:SOMETHING GameData;//...int handle = open ("FileName.sth", O_CREAT | O_WRONLY | O_BINARY);if (handle != -1) write (handle, &GameData, sizeof (GameData));close (handle);
If you want to read the data again, just do the following:
code:int handle = open ("FileName.sth", O_RDONLY | O_BINARY);if (handle != -1) read (handle, &GameData, sizeof (GameData));close (handle);
Ok, maybe not the best solution, but working.
You should have a look at the descriptions of these functions contained in your compiler's help. There are always examples that show you this stuff better then I do here.
Have a nice day... Andreas
I have tried the code that you have gaved me and I've got a bunch of errors... I have checked the MSDN Library, but there are lots of functions called open... What can I do?
Thanks!
[This message has been edited by BenB (edited October 02, 1999).]
code:#include fcntl.h#include io.h
Should work fine, now...
Bye!
[This message has been edited by Melo (edited October 02, 1999).]
[This message has been edited by Melo (edited October 02, 1999).]
I have no idea how to save data in a file. can someone link to an article, or tell me how to do it?
Thanks!
code:FILE *MyFile;MyFile = fopen("c:\whereyouwantit", "wb"); // or rb, wt, rt etc.//write to the file with such thing as fwritefwrite(MyFile, "this is what you write");//orfwrite(MyFile, "point 1: %d", x);//reading is with fread//closefclose(MyFile);//or if you have multiple files op_fcloseall(); // to close them all at once
though the help can be helpful to you, in this case....
you can also use functions like
fputc or the like
------------------
Dance with me......