I'm experiencing something strange here:
In the code below I malloced filename to the strlen of the category name, + 4 to add ".dat". When I do that I get stuffing in my string.
Now my question: When I malloc filename to 1 (just to test) the filename string gets filled correctly. This is kinda strange to me, does strcat reallocs or something ?
Code:
int get_questions(char*** stringarray, char* category)
{
char* filename = NULL;
int i = 0;
filename = malloc(strlen(category)+4);
//filename = malloc(1);
getfilename("rubrieken/", category, filename);
printf("%s", filename);
return i;
}
void getfilename(char* dir, char* string, char* filename)
{
strcat(filename, dir);
strcat(filename, string);
strcat(filename, ".dat");
}