初学者编译链表系统程序求改正
主要是想编译基于链表的系统,现在实现了链表建立,链表存储,读取输出不能执行,求大神指点一下程序代码:
#include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct tamers { char tname[20]; int tno; char tsex[2]; char tmuseum[10]; int tage; char tshowtime[20]; char tshowname[20]; int ano; struct tamers *next; }TMR; int save(); void output(); TMR*shuru(); TMR * read_from_file(); int main() { shuru(); save(); output(); return 0; } TMR*shuru() { TMR*head,*p,*q; char tname[20]; p = (TMR *)malloc(sizeof(TMR)); head = p; q = p; q ->next = NULL; printf("请输入驯养员信息 输入名字为'none'时结束:\n"); printf("名字:"); scanf("%s",&tname); while(strcmp(tname,"none")!=0) { p = (TMR*)malloc(sizeof(TMR)); strcpy(p->tname,tname); printf("编号:"); scanf("%s",&p->tno); printf("性别:"); scanf("%s",&p->tsex); printf("年龄:"); scanf("%d",&p->tage); printf("场馆:"); scanf("%s",&p->tmuseum); printf("表演时间:"); scanf("%s",&p->tshowtime); printf("节目名称:"); scanf("%s",&p->tshowname); printf("宠物编号:"); scanf("%d",&p->ano); q->next=p; q=q->next; printf("请输入驯养员信息 输入名字为'none'时结束:\n"); printf("名字:"); scanf("%s",&tname); } q->next=NULL; return head; } //存储 int save (TMR*head) { TMR * p; FILE * fp; int flag; p=head->next; fp= fopen("tamers.txt","w"); if(NULL==fp) { printf("文件打开失败"); return 0; } while(NULL!=p) { flag=fwrite(p,sizeof(TMR),1,fp); if(flag!=1) { printf("write failed"); return 0; } p=p->next; } fclose(fp); free(fp); return 1; } //读取 /*TMR *read() { FILE*fp; TMR *p; head=(TMR*)malloc(sizeof(TMR)); head->next=NULL; fp=fopen("tamers.txt","r"); while(!eof(fp)) { p=(TMR*)malloc(sizeof(TMR)); fread(p,sizeof(TMR),1,fp); p->next=head->next; head=p; } fclose(fp); free(fp); return head; }*/ TMR * read_from_file() { FILE * fp; TMR*head,*p; head=(TMR*)malloc(sizeof(TMR)); head->next=NULL; fp=fopen("tamers.txt","r"); while(!eof(fp)) { p=(TMR*)malloc(sizeof(TMR)); fread(p,sizeof(TMR),1,fp); p->next=head->next; head=p; } fclose(fp); free(fp); return head; } void output(TMR*head) { head=read_from_file(); TMR * p; p=head->next; while(p!=NULL) { printf("姓名:%s;\t编号:%d;\t性别:%s;\t年龄:%d;\t场馆:%s;\t表演时间:%s;\t节目名称:%s;\t宠物编号:%d;\n", p->tname,p->tno,p->tsex,p->tage,p->tmuseum,p->tshowtime,p->tshowname,p->ano); p=p->next; } }