I have a function that returns a char*. No problem. But I need to concatenate another array with the results of this function. I'm getting a segmentation error.
What am I doing wrong? Thanks.
Code:
//this next line outputs correctly so I know my function is working
fprintf(stdout, "%s\n", get_filename(selection));
char* temp;
//but this next line causes a segmentation fault
strncpy(temp, get_filename(selection), sizeof(get_filename));
//never runs
fprintf(stdout, "here");
my function if interested
Code:
char* get_filename(char selection[]) {
char* end;
char* start = strchr(selection,'[');
if(start == NULL) {
return NULL;
}
start ++;
end = strchr(start ,']');
if (end == NULL) {
return NULL;
}
*end = 0;
return start;
}