This is a beginner question, but please bear with me. I'd like to pass in a char* to a function, and have it populated, with the contents of multiple existing strings. Here's what I have (and doesn't work)
int func(char *out) {
int i;
int x = 10;
int y = 10;
char array[x][y];
out = malloc(x * y + x);
memset(out, 0x00, strlen(out));
for (i=0; i<x; i++) {
strcat(out, array[i]);
strcat(out, "\n");
}
}
//main
char *result;
func(result);
strlen(out)! Read up whatstrlendoes (or how C strings work, for that matter). You need to sayx * y + xinstead. And absolutely make sure that everyarray[i]is null-terminated.