Advertisement

PAK files

Started by November 12, 2001 03:18 PM
10 comments, last by Bezzant 23 years ago
quote: Original post by Lunatic Raven
It seems to be if the crazy ASCII stuff is being added to the end, your sting may be too bigger than what you are loading in, and it is just showing what is already stored in there. You may also be reading in past the length of the text in the text file and by doing that you are accessing memory allocated for something else.


thats what i thought, that the char array was too big to hold the string. i tested that by making it smaller, however that only cut the last few letters of the file off, yet the extra ascii characters remained there
quote: Original post by Anonymous Poster
Are you sure the string received is null terminated?

fread returns the number of bytes read so try this:

#define ENGINE_FILE_SIZE 138

int bytes_read;
char enginetxt[ENGINE_FILE_SIZE + 1];

// read
bytes_read = fread(enginetxt, sizeof(char), ENGINE_FILE_SIZE, File);

// null terminate
enginetxt[bytes_read] = 0;


it wasnt, but i null terminated it, had it show how many bytes it wrote, it was 36, which is corect (i started over with a new PAK file that had a different txt file in)

its weird, it prints the contents out then this: "H«B" is added.... its not as bad anymore, when i started there was about 8 characters, but null terminating it, changing the size of the char array hasnt made a difference either. strange

This topic is closed to new replies.

Advertisement