I only have this one problem left in check50. https://sandbox.cs50.net/checks/e3382282d5e64259adec1cc4f51b17de
I'm pretty sure the problem is in "load" (but, I could be wrong). I know it is tricky to write user input to pipe, but, if we could read bytes and store it in *content & *length, shouldn't there be a way (an easy one, I hope) to write into it? I've looked around for ideas from the forum, but it remains unclear. Here's a post where this problem was also mentioned.
I feel like I'm missing a step in load to write user input to ".php?". Can anyone please refer me to some readings where I can learn to do this? I don't think it is mentioned anywhere in materials cs50 gave us for edX students. It makes it difficult for someone like me who has NULL background of computer science to complete this pset with flying colours.
Anyway, here's my "load" codes:
bool load(FILE* file, BYTE** content, size_t* length)
{
// declare variables
*content = NULL;
*length = 0;
BYTE buffer[BYTES];
if(file == NULL)
return false;
// iterate over file, bytes by bytes
for(int c = fread(buffer, 1, BYTES, file); c != 0; c = fread(buffer, 1, BYTES, file))
{
*content = realloc(*content, *length + c + 1);
if(*content == NULL)
return false;
memcpy(*content + *length, buffer, c);
*length += c;
}
return true;
}
Thanks beforehand.