0

Pset6 Web-server... In Parse function, how do you store absolute-path at the address in abs_path?

bool parse(char* line, char* abs_path, char* query)
{
    char* absolute-path;

    // assume I've left out code that assigns text to absolute-path
    abs_path = malloc(40);
    strcpy(abs_path, absolute-path);

    // assume everything else is implemented correctly
    return true;
}

If I run debugger, in main, after this function is implemented, abs_path reverts back to what was passed into it. abs_path doesn't retain the value of absolute-path. How would I get it to store and retain the value of absolute-path?

2

Good troubleshooting. This line abs_path = malloc(40); gives the local abs_path a new address. Alas, as you have discovered, main is looking at the "original" abs_path address acquired here char abs_path[LimitRequestLine + 1];. The local abs_path is a pointer to already-allocated memory. There is no reason to allocate more/different memory.

| improve this answer | |

You must log in to answer this question.

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