0

I am pretty sure my other functions work - I pass all check50, except for the last line in check50 server1, where it's written TODO and the same for check50 server2.

However, when I ran server in IDE, as an output I get only lines of code. It's similar to "view page source" option. And an error in connection. Unfortunately, I cannot access the IDE now to copy at least a snippet of that output.

Thanks!

 char* indexes(const char* path)
 {
        char* ind_php = "/index.php";
        char* ind_html = "/index.html";

        char* inx = malloc(sizeof(strlen(path) + strlen(ind_html) + 1));
        strcpy(inx, path);
        strcat(inx, ind_html);

        if (access(inx, F_OK))
        {
             return inx;
        }


        strcpy(inx, path);
        strcat(inx, ind_php);

        if (access(inx, F_OK))
        {
           return inx;
        }

     free(inx);
     return NULL;
 }

EDIT. Do not use F_OK, but R_OK. Also, if access != -1. :) HTH.

1 Answer 1

1

according to the specs, you should first check for index.php's existence and return a path to it, if it exists. then check for index.html's existence, and return a path to it, if it exists. otherwise, you just return NULL.

see http://cdn.cs50.net/2016/x/psets/6/pset6/pset6.html#indexes_2 for more!

8
  • Oh, I have never thought that would be a problem. Unfortunately, I can't access the IDE, it's been unavailable for hours, but I'll accept your answer. And thanks a bunch, you're always so helpful! :)
    – Lana
    Commented Mar 15, 2016 at 19:46
  • Finally, I've managed to access my workplace, but this still doesn't work. :/
    – Lana
    Commented Mar 17, 2016 at 8:25
  • @Lana what exactly doesn't work?
    – kzidane
    Commented Mar 17, 2016 at 9:22
  • Well, I've modified this function, I used fopen in the second version. Using printf, I saw it worked, but I get errors when I try to run server or check50. In check50 server2, all is good, but the last lines - TODO and I think it's because of this function.
    – Lana
    Commented Mar 17, 2016 at 10:30
  • @Lana I don't think fopen is ever needed in this function.
    – kzidane
    Commented Mar 17, 2016 at 17:35

You must log in to answer this question.

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