Memory files in C
(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]
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
Or have I missed the point of your question?
Jacob Marner, M.Sc.
Console Programmer, Deadline Games
Jacob Marner, M.Sc.Console Programmer, Deadline Games
Ahh, fread(), thank you .. Also I could just make an integer table and load the file to memory manually using fgetc. Doh..
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);
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);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement