UPDATE
I've tried to make the load function smaller without using my own addByte()
function. Instead I used the BYTE* buffer variable as an array and added each b from the for-loop of my first load function for(int b = fgetc(file); b != EOF; b = fgetc(file))
etc. on the i'th place of buffer. Here is my current code:
bool load(FILE* file, BYTE** content, size_t* length)
{
int i = 0;
size_t fileSize = 0;
*content = NULL;
BYTE *buffer = NULL;
for(int b = fgetc(file); b != EOF; b = fgetc(file)){
fileSize++;
buffer = realloc(buffer, fileSize);
buffer[i] = b;
i++;
}
*length = fileSize;
*content = buffer;
return true;
}
The only thing I found out in the last days was that feof(file)
's integer value is 0 and the integer value of EOF
is -1. Due to the fact that no functions like stcpy()
or memcpy()
are used I think that there is something basic I don't understand. Maybe it is simple pointer arithmetic? Maybe I don't understand realloc()
? Maybe it is something with the null-terminator \0
or I don't understand a concept fully yet. I'm starting to freak out honestly.