I have struggled with the server.c for half a month. Now everything seems OK except for the html page.When I firstly type in the name, it shows correctly.
But the second time,I type in another name-dana, it shows that the memory of the first name is not cleared.
And the check50 always returns false,too.
Is it because there is something wrong with the load function?
bool load(FILE* file, BYTE** content, size_t* length)
{
// ensure pipe is open
if (file == NULL)
{
return false;
}
// initialize the pointers
*content = NULL;
*length = 0;
char* file_content = NULL;
// allocate memory on the heap
file_content = malloc(1);
if (file_content == NULL)
{
return false;
}
//i for getting the size of content
int i = 0;
for (int c = fgetc(file); c != EOF; c = fgetc(file))
{
file_content[i] = (char) c;
i++;
file_content = (char*) realloc(file_content, sizeof(char)*(i+1));
}
//increase size for every loop
//reallocate memory of file_content
*content = file_content;
*length = i;
return true;
}
parse()
's fault. You're probably doing something wrong withquery
. But these two reds on check50 are probablyindexes()
fault.