我完成了所有的功能,但是我的代碼沒有通過第二次檢查。我不確定問題出在哪裏,但可能是在我的加載或索引函數中,因爲我的代碼成功通過了第一次檢查。有人可以幫我弄清楚嗎?噢,出於某種原因,我的GDB不工作。提前致謝!cs50 pset6加載或索引函數出錯
這裏是我的代碼:
char *indexes(const char *path) {
char *copy = malloc(strlen(path));
strcpy(copy, path);
char *php = "/index.php\0";
char *html = "/index.html\0";
char *check_php = malloc(strlen(copy) + strlen(php));
char *check_html = malloc(strlen(copy) + strlen(html));
check_php = strcat(copy, php);
check_html = strcat(copy, html);
if (access(check_php, F_OK) == 0)
return check_php;
else
if (access(check_html, F_OK) == 0)
return check_html;
return NULL;
}
bool load(FILE *file, BYTE **content, size_t *length) {
char *store = malloc(5000);
int count = 0;
char c;
do {
c = fgetc(file);
if (feof(file))
break;
else
if (count % 5000 == 0)
store = realloc(store, count + 5000);
store[count] = c;
count++;
} while (true);
*content = &store[0];
*length = count;
return true;
}