strcpy(s,lookup(line));
After gdb: Program received signal SIGSEGV, Segmentation fault. __strcpy_ssse3 () at ../sysdeps/i386/i686/multiarch/strcpy-ssse3.S:84
I would look for another way, for example:
// copy line to new string
char* temp = malloc(strlen(line) + 1);
if(temp == NULL)
{
free(temp);
return false;
}
strcpy(temp, line);
i don't know how is possible to resolve server without using gdb, this is a fundamental skill that you have to learn. I also do not know what you intend to use lookup, if only returns a string with the MIME type of file, you have to analyze line and see that it fulfills the specifications
EDIT
Come to lookup a pointer question: `const char* lookup(const char* path), means that lookup, receives a constant pointer, really it means that we have a string, which already exists and will not change, there is no need to malloc, calloc or realloc; const char * path means I have a pointer to the start of the string path, but can also access each and every one of his characters. We stopped for a moment before writing code "I just need to find a characteristic of path, that is useful to me to determine the file extension".
if you look a time all file extensions have a point: '.' and now we see a little problem specifications suggest us use features like strcasecmp, strcpy, and / or strrchr, it is our duty to learn to use them. char * strrchr (const char * s, int c); It is perfect for us, returns a pointer to the last occurrence of the character c in the string s. We have function (strrchr), we have the character we want( a point) and we have a constant string ( const char* path). therefore we can do:
char * point = strrchr (path, '.'); // Returns a pointer to the character point
point is a string (char *), so if exists point we have a chain that begins in that character, ie if path ends with .html point is precisely ".html" exactly what we want. Now we can use a very useful function in this case strcasecmp, our chain point, and a lot of IF conditions, I think this is enough to start.
EDIT 2
if (abs_path[strlen(abs_path) - 1] != '/')
char* index = indexes(path);
Are the lines of code that cause the error because abs_path is not correct, and strlen is 0. Parse does not work, I understand your idea, but not executed correctly.
for(int i=0;i<strlen(line);i++)
{
int flag=0,j=0,q=0;
Every time begins FOR, your control variables initialized zero, so not fulfill its function and abs_path is '' at the end of parse.
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)