0

I am trying to implement Pset6 but I'm having a huge problem with segmentation faults caused by strstr or strchr. The offending lines are

printf("OK %s\n", reqLine); 
tempStr = strstr(reqLine, "HTTP/1.1");

Where tempStr is a char *. I did the printf just for my own observation and the terminal out put is

OK GET /cat.html HTTP/1.1
Segmentation fault (core dumped)

So reqLine isn't NULL. The segmentation fault always occurs here even if I search for some other string, for instant "/" instead of "HTTP/1.1". I use strstr elsewhere in my program in the exact same way and have no issues. I'm completely at a loss as to why this is happening. I have seen others have similar issues except they are making obvious mistakes such as not checking if the return value is NULL before going ahead and trying to use the result later on. I have no idea why this particular code snippet is failing.

1 Answer 1

0

Where is tempStr declared? I'd like to see that line of code as well. There may be a typo there.

You must log in to answer this question.

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