// TODO: Pseudocode

// Allocate memory for (path/index.html and path/index.php, respectively)

// copy path into char *pi      

// concatenate 'pi' with '/index.html' ('/index.php')   

// check if pi exixsts using access()

    // if it does return pi 
       ('path/index.html' or 'path/index.php', respectively)

// else free 'pi' and return NULL

Is this the way to go?


The function signature of strstr is

char *strstr(const char *haystack, const char *needle)

Since you have declared needle a const char*, you are violating the contract. I recommend further reading in the doc, specifically

These functions return a pointer to the beginning of the substring, or NULL if the substring is not found.

in the context of your if (needle == 0) statement.

PLEASE NOTE: This answer no longer makes contextual sense because of edits to the orginal question.

  • I'm still not clear what the task here is!? Should '..../hello.php' become '...../hello.php/index.php ? If this is the case, why would we want that? My code now compiles after editing. However, I doubt it does what it should. – gado007 Feb 29 '16 at 18:21
  • indexes only executes if abs_path is itself a directory. hello.php is not a directory. To see if your code works you would need: 1) a subdirectory of path/to/root. 2) an index.html (or index.php) that resides in that directory. Then browse to {home}/subdir. The browser should display index.hmtl or a dir list if neither index file exists. – DinoCoderSaurus Mar 1 '16 at 17:27
  • DincoderSaurus, you have not answered the question. In fact, you further obfuscated it. Some of us have trouble figuring out what is required here. Like me. – ihor Mar 6 '16 at 2:10
  • @ihor Sorry for confusion. I answered the original question, which was subsequently edited. – DinoCoderSaurus Mar 6 '16 at 22:03
  • Indeed, I edited my original post several times. DincoderSaurus's comments helped me improve. What would be a better way to handle such a situation next time? Leaving the original post as it is and simply discuss the changes in the comment section? – gado007 Mar 11 '16 at 17:40

You must log in to answer this question.

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