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);
A
char*is just a pointer, passing it in doesnt let you pass a new one back out again. You need to pass achar**like so:You then feed the function somewhere to put the pointer like so: