Jump to content

  • Log In with Google      Sign In   
  • Create Account

Using File


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 BenB   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 October 1999 - 01:00 AM

Hello!
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!

Sponsor:

#2 MikeD   Members   -  Reputation: 158

Like
Likes
Like

Posted 01 October 1999 - 07:20 AM

If you want help I think you're going to have to be more specific.
Do you mean you're programming and you're trying to save, in which case what programming language are you using?
Otherwise......

#3 BenB   Members   -  Reputation: 122

Like
Likes
Like

Posted 01 October 1999 - 08:40 AM

Hi!
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...


#4 Melo   Members   -  Reputation: 122

Like
Likes
Like

Posted 01 October 1999 - 09:46 AM

Here comes a solution for C++:

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


#5 BenB   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 October 1999 - 01:53 AM

What files do I have to include?
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).]


#6 Melo   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 October 1999 - 11:29 AM

No problem...
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).]


#7 Melo   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 October 1999 - 11:33 AM

Hmmm...does the UBB handle the Text in these brackets as HTML?!

#8 CJ   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 October 1999 - 01:00 AM

Why not use:

code:

FILE *MyFile;

MyFile = fopen("c:\whereyouwantit", "wb"); // or rb, wt, rt etc.

//write to the file with such thing as fwrite

fwrite(MyFile, "this is what you write");
//or
fwrite(MyFile, "point 1: %d", x);

//reading is with fread

//close
fclose(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......





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS