新人请教:返回出错,请高手详解
#include<stdio.h>#include<stdlib.h>
typedef struct island{
char *name;
char *opens;
char *close;
struct island *next;
}island;
void display(island *start){
island *i = start;
for(;i != NULL;i = i->next){
printf("Name:%sopen:%s - %s\n\n",i->name,i->opens,i->close);
}
}
void release(island *start){ //释放内存
island *i = start;
island *next = NULL;
for(;i != NULL;i = next){
next = i->next;
free(i->name);
free(i);
}
}
island create(char *name){ //创建内存
island *i = malloc(sizeof(island));
i->name = strdup(name);
i->opens = "09:00";
i->close = "17:00";
i->next = NULL;
return i;
}
int main(){
island *start = NULL;
island *i = NULL;
island *next = NULL;
char name[80];
for(;(fgets(name,80,stdin))!= NULL;i = next){
next = create(name);
if(start == NULL)
start = next;
if(i != NULL)
i->next = next;
}
display(start);
release(start);
system("pause");
return 0;
}