I have this snip of code in order to load some files into memory, into data .
There are three files in the same path that I would like to read: an XML, a PNG and a TTF font file. All three are successfully open and its size shown in size. Unfortunatelly, only the XML and PNG are read into data.
The TTF file gets the correct size, the equally proper result of fread, but an empty (not null) data and empty fp->_base.
char* data;
size_t size = 0;
FILE *fp = fopen(completeFilePath, "rb");
if (fp != NULL) {
fseek(fp, 0, SEEK_END);
size = ftell(fp);
fseek(fp, 0, SEEK_SET);
data = new char[size];
size_t result = fread(data, sizeof(char), size, fp);
fclose(fp);
}
Could you bring some light into this problem?
Greatly appreciated.
The NUL byte doesn't magically mean the end of anything it's found in. It's just a convention used by a lot of C standard library functions. It's perfectly valid for a file to contain a NUL byte and then have more characters after. This is exactly what's in your data
: a NUL byte and then more characters. So it's not actually empty; you're just incorrectly assuming that it is.