0

The server responds with code 200 OK. But no files load up, instead some random characters pop up.

bool load(FILE* file, BYTE** content, size_t* length)
{
    BYTE* buffer = malloc(sizeof(BYTE));
    *length = 1;

    while(fread(buffer, sizeof(BYTE), 1, file) == 1)
    {
        *length = *length + 1;
        buffer = (BYTE *) realloc(buffer, *length);
    }

    *content = buffer;

    return true;
}
1

A small problem is initializing *length to 1. The *length you calculate will be +1. That may not pose a problem to a browser, but check50.server2 will be all frowns.

The bigger problem is in your fread. No matter how big the allocation of buffer, where is the byte that you read going to go? Always and ever into buffer[0]. You need to "push it along". If you initialize *length to 0, you could account for the next byte in the realloc.

0

I think you have a problem with *length, try turning it into an int first and finally assigning it to *length, outside the loop and start with 0 and not with 1.

0

Try adding *content = NULL;to the beginning of the function. This will ensure you are not simply adding to previous information in *content.

Also, you will be able to use fread to get the files to load but you will not be able to get hello.html to work because it is a stream of data (pipe), rather than a file. fgetc will work for this purpose.

1
  • You absolutely can use fread to load all files. You cannot use functions like fseek or ftell on pipe streams. Jun 9 '16 at 11:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .