Skip to main content
deleted 89 characters in body
Source Link
MARS
  • 5.2k
  • 3
  • 14
  • 23
line[3]!=32

isn't correct, should be line[3] = '32' or ' ', hope it will help.

line[3]!=32

isn't correct, should be line[3] = '32' or ' ', hope it will help.

added 609 characters in body
Source Link
MARS
  • 5.2k
  • 3
  • 14
  • 23

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.

line[3]!=32

isn't correct, should be line[3] = '32' or ' ', hope it will help.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

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.

line[3]!=32

isn't correct, should be line[3] = '32' or ' ', hope it will help.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

added 1 character in body
Source Link
MARS
  • 5.2k
  • 3
  • 14
  • 23
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 = strcatstrrchr (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.

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 = strcat (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.

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.

added 1443 characters in body
Source Link
MARS
  • 5.2k
  • 3
  • 14
  • 23
Loading
Source Link
MARS
  • 5.2k
  • 3
  • 14
  • 23
Loading