所以我试图在从函数返回后打印出一个 char* 数组,但我不断收到段错误。
char* return(node *n){
node* p = list->head;
int count = 0;
int size = 0;
while(p != NULL){
size += strlen(p->name);
count++;
p = p->nxt;
}
size = size + 1; // for the '\0'
char * arr[count][size];
p = list->head;
count = 0;
while(p != NULL){
strcpy(arr[count], p->name);
count++;
p = p->next;
}
return arr;
}
然后我去尝试在某个节点上的 main 方法中打印出来。我得到一个分段错误。
char* test = return(node1);
for(i = 0; i < 5; i++){
printf("%s", test[i]);
}