Thanks to an answer on an earlier question tonight, server.c seems to work perfectly on every file except for cat.jpg. I checked in GDB, and the path is processing perfectly, as is the MIME type. But when I try to load that file, I just get a white screen. In cat.html, it shows the broken image icon.

I searched for an answer, but all of the previous mentions of this problem that I could find were from an older version of the pset, which apparently involved also coding the response to the client. But, since in the current version that was pre-coded, I can only assume that the problem is in my load function. I'm not sure where to look, however, as everything else loads perfectly. Heck, this is the same technique I used in dictionary.c, except I was storing into a trie there.

BYTE* buffer = malloc(sizeof(BYTE));

int count = 0;

for (BYTE c = fgetc(file); c != EOF; c = fgetc(file))
    buffer[count] = c;
    buffer = realloc(buffer, ((count + 1) + sizeof(BYTE)));
    if (buffer == NULL)
        return false;

*content = buffer;

*length = count;

return true;

I think the problem is because of BYTE c = fgetc(file). Change it to int c. that will do it!

  • Nope, that doesn't work. (I just tested to make sure my understanding wasn't off, but it indeed didn't work.) First of all, fgetc gets a single byte of data, and an int is 4 bytes. It will cast the data, but that means the file would be stored with the wrong bytes to make the file readable. Even not counting that, the function as defined by the pset requires returning a pointer to bytes, not ints. Thanks for answering though! I managed to pass the pset even without a working cat.jpg, though not the 1.0 I managed on everything else. :)
    – Fobok
    Feb 28 '16 at 1:10
  • 1
    The problem is with the fgetc function, I was stuck on the same part and realised that although a char is 1 byte, fgetc will only get a char, this works for the text files but not for the image files. I don't want to come out and give you the answer because it will spoil the fun of working it out, but the key is in your pset4 recover!
    – Claire
    May 28 '16 at 19:00
  • Claire, you're amazing!!
    – Michael
    Dec 25 '16 at 3:16

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