This pset has been a truly humbling experience. I was able to get lookup working (I think, based on my testing), and parse I could think of a general idea and then had to work through the specifics with a lot of gdb debugging and a question on the forum.
For this part of the problem, I'm not even sure I'm on the right track. None of the check50 feedback has changed at all, and I'm not sure how else to test this one (don't know how to write a test program for it). Is there a way to curl test just this part, or is that not what curl does?
Here's my code:
bool load(FILE* file, BYTE** content, size_t* length)
{
char* buffer = calloc(1, BYTES); //1
int sizeCounter = BYTES; //2
do
{
fread(&buffer[sizeCounter - BYTES], BYTES, 1, file); //3
if(feof(file)) //4
{
break;
}
sizeCounter += BYTES; //5
buffer = realloc(buffer, sizeCounter); //6
}
while(true); //7
*content = buffer; //8
*length = sizeCounter; //9
return true;
}
And here's my thinking, in pseudocode:
- Set up a buffer with some memory the size of Bytes (512)
- Set up a counter that is initially the same size as the buffer.
Start looping:
- Read information from file into the buffer, starting back at the beginning of the last allocated block of memory
- Check to see if we're at the end of the file, and if so, break.
- Since we're not at the end of the file, increase the file size counter
- realloc more memory so the buffer is ready to keep reading
- Keep looping
When the loop is finally over:
- Set the content to the buffer
- Set the length to the sizeCounter.
Am I on the right track here? Is the check50 just not working because I haven't written the indexes method yet? Or is it something else?
Thanks again for any help,
-Brian