i want to implement parse function by breaking the line into 3 parts using strtok() function, store those char* in array and check if they complete conditions we have in pset. But something goes wrong. Here's my code for this function, any kind of help will be apriciated.
bool parse(const char* line, char* abs_path, char* query)
{
char *aray[3];
char str[strlen(line)+1];
strncpy( str, line, strlen(line)+1 );
char* pch;
pch = strtok(str, " ");
int index = 0;
while (pch != NULL)
{
aray[index] = pch;
index++;
pch = strtok(NULL, " ");
}
if (strncmp(aray[0], "GET", 9) != 0)
{
error(405);
return false;
}
else if (aray[1][0]!='/')
{
error(501);
return false;
}
else if (strchr (aray[1], '"')!=NULL)
{
error(400);
return false;
}
else if (strncmp(aray[2], "HTTP/1.1", 7) !=0)
{
error(505);
return false;
}
else
{
// abs_path = aray[1];
return true;
}
}
Made a few general changes, now check50 gives me next errors which i dont understand: https://sandbox.cs50.net/checks/020d4c58104f406d91c2bee120da07d3