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

Loading A Entire Filfe from disk to MEM

This topic is 5972 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

FILE* inFile = fopen("map.txt", rb);
int length = 0;
int startPosition;
char* fileData;
startPosition = ftell(inFile);
fseek(inFile, 0, SEEK_END);
length = ftell(inFile);
fseek(inFile, 0, startPosition);
fileData = (char*)malloc(length * sizeof(char));
fread(fileData, 1, length, inFile);

I think that should do it. Now, a copy of the data contained in the file is stored in memory, and fileData is a pointer to it. So to use it, you would do something like:
char* currentPosition = fileData;
while(*currentPosition++ != NULL)
if(*currentPosition == TILE_TYPE_ONE)
else if(*currentPosition == TILE_TYPE_TWO)

Or something like that.


Share this post

Link to post
Share on other sites