I am taking this course online. I do not have anyone to ask for help that knows anything about coding so I rely 100% on this discussion board (and the internet in general) for help. I am having trouble with pointers. I couldn't finish Pset5 so I quit stressing and went ahead with Pset6 in hopes that I could learn something that would help. I get so frustrated because I know exactly what I want to do, but I do not know how to execute it in code.
I am working on Parse and I am going through each rule and trying to get it to pass check50 and gdb. I think I am doing everything logically, but I keep getting it wrong.
This is what I am having trouble with: I have created const char* for known points in "line": one for the first space between the method and the request line, one for the 2nd space between the request line and the version, and one to "\r" of CRLF. I malloc memory for the method, request line, and the version and store it in a char* for each using, as an example, char* method = malloc(sp1 - line), where sp1 is a const char* for the first space in line. I then strncpy(method, line, strlen(method) in order to copy "GET" to method. Then I if (strcmp(method, "GET") != 0) ...error(405)...
I have tried this and countless other variations with each rule and sometimes it works and sometimes it doesn't. I am totally lost because even writing all of the code out on paper and checking and double checking it seems correct but when I compile and run check50 soemething is always wrong.
Somebody please tell me if this is the completely wrong way of going about solving this problem.