I'm really confused about what is wrong with my code as load works for certain files but not others and the reading of the file isn't something that is altered in any of the functions we're tasked with.

I've included check50 results and code here: http://pastebin.com/v3eU24Zt

My load function reads in character by character, with GDB I watch it read in HTML, ico, js etc. fine but it doesn't read in anything for a jpg.

I also don't understand why it can't handle, HtMl for example as I use strncasecmp in lookup so case shouldn't matter right?

1 Answer 1


for (char read = fgetc(file); read != EOF; read = fgetc(file)). read cannot be a char. Because of internal casting in fgetc, this can return a "false eof", and almost always does on binary (image) files. Some char in the image files is being cast to the int -1. EOF is defined (in stdio.h) as -1. The loop ends prematurely. If you cast c as an int (instead of char), it should work. This article may help clarify the point.

\ expected output, not an exit code of 0 from check50 usually indicates a seg fault. Looks like building query in parse has a bug.

These two failures point to a bug in indexes.

:( Requesting /test/ outputs /test/index.html
:( Requesting directory containing index.php outputs index.php
  • Thanks again @DinoCoderSaurus Okay, so indexes is fixed. The problems remaining are completely baffling. for cat2 and cat3 checks I'm using strcasecmp and I've tried strcasestr but to no avail? other forum posts seem to concur with those methods. Another big one, when line gets to parse it doesn't include the question mark if say I request - /hello.php? in line I'm seeing - GET /hello.php HTTP1.1\r\n - as soon as it hits parse.
    – clomas
    Jul 25, 2016 at 13:49
  • Could you update the pastebin with all your functions and current check50 results? How are you detecting "when line gets to parse it doesn't include the question mark"? printf? gdb? other? Jul 25, 2016 at 14:28
  • here you go: pastebin.com/pH2tVk8q sandbox.cs50.net/checks/caafa32bbb7d43c990de3e11e0f3c242 As my functions are close to completion I've put an expiration on the pastebin. Thanks!
    – clomas
    Jul 26, 2016 at 10:39
  • Looks like all your problems are belong to parse. This sizeof(LimitRequestLine) is bad in a couple of places. not sizeof! This char* findq = strchr(request_target, 'q'); is bad. Where is the 'q' in the php tests? If there is a query, abs_path will include it. Keep workin' it with gdb and/or printfs. My preferred print format when making sure a string ends in the right place is "%s<-". That way the eyes won't be fooled by non-printing characters. Jul 26, 2016 at 11:58
  • PS lookup looks ok. I suspect cat2.HTML and cat3.HtMl fail because of the missallocations in parse. LimitReqestLine is integer, sizeof(LimitRequestLine) is 4, /cat2.HTML is longer than that. Jul 26, 2016 at 12:06

You must log in to answer this question.

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