Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Viajero

Memory files in C

This topic is 5728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

(How) can I make a memory file (FILE *) in C (standard lib)? I need to do both, read from and write to a file. So I guess I could use a temporary FILE *, which is loaded in to memory. Or do I have to open the file with "r+" and mess around with the fseek(), fpos() etc? I'm making a simple dos encrypter/decrypter prog, in case you wondering. [edited by - viajero on January 19, 2003 8:06:21 AM]

Share this post


Link to post
Share on other sites
Advertisement
Erhmm, why don''t you just take your file and use fopen()/fread()/fclose() to load it entirely into memory. And then you have the file contents in memory for you to mess around with until you have to write it out again.

Or have I missed the point of your question?


Jacob Marner, M.Sc.
Console Programmer, Deadline Games

Share this post


Link to post
Share on other sites
Ahh, fread(), thank you .. Also I could just make an integer table and load the file to memory manually using fgetc. Doh..

Share this post


Link to post
Share on other sites
Got one more question. If I want to "rewind" the file, is this the correct way to do it?

FILE *f1;
int i;
fpos_t *pos;

f1=fopen("f.txt","r");

fgetpos(f1, pos); //Seems like I''m passing just the value of pos to the function..

while(fgetc(f1)!=EOF) i++;

fsetpos(f1, pos);

Share this post


Link to post
Share on other sites
Yes you can do it that way. But if you want to rewind it all the way to the start the preferred way is to use

fseek(file, 0, SEEK_SET);


Jacob Marner, M.Sc.
Console Programmer, Deadline Games

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!