33,311
社区成员
发帖
与我相关
我的任务
分享
scanf("%d%s%d%d%d%d",&(p->num),(p->name),&(p->score[0]),&(p->score[1]),&(p->score[2]),&(p->score[3]),&(p->score[4]),&(p->score[5]));
struct achieve{
int num;
char name[20];
long score[6];
struct achieve *next;
}tab_achieve ;//学生信息结构体
void f8(FILE * pf){//这个是排序函数
struct achieve *top,*p,*p0;
fseek(pf,0,SEEK_END);
if((ftell(pf)/sizeof(struct achieve))>1){
p=(struct achieve *)malloc(sizeof(struct achieve));
rewind(pf);
fread(p,sizeof(struct achieve),1,pf);
top=p;
top->next=NULL;
while(!feof(pf)){
p0=top;
p=(struct achieve *)malloc(sizeof(struct achieve));
fread(p,sizeof(struct achieve),1,pf);
if((strcmp(top->name,p->name))<=0){
p->next=top;
top=p;
}
else{
while((strcmp(p0->name,p->name))>0&&(p0->next!=NULL)){
p0=p0->next;
}
if(p0->next!=NULL){
p->next=p0->next;
p0->next=p;
}
else{
p0->next=p;
p->next=NULL;
}
}
}
list(top);
}
else{
if((ftell(pf)/sizeof(struct achieve))==1){
p=(struct achieve *)malloc(sizeof(struct achieve));
fread(p,sizeof(struct achieve),1,pf);
p->next=NULL;
list(p);
} //此处写上输出函数}
else
printf("文件里没有任何信息\n");
}
}
先帮楼主把程序排一下void f8(FILE * pf){//这个是排序函数
struct achieve *top,*p,*p0;
fseek(pf,0,SEEK_END);
if((ftell(pf)/sizeof(struct achieve))>1){
p=(struct achieve *)malloc(sizeof(struct achieve));
rewind(pf);
fread(p,sizeof(struct achieve),1,pf);
top=p;
top->next=NULL;
while(!feof(pf)){
p0=top;
p=(struct achieve *)malloc(sizeof(struct achieve));
fread(p,sizeof(struct achieve),1,pf);
if((strcmp(top->name,p->name))<=0){
p->next=top;
top=p;
}
else {while((strcmp(p0->name,p->name))>0&&(p0->next!=NULL)){
p0=p0->next;
}
if(p0->next!=NULL){
p->next=p0->next;
p0->next=p;}
else {
p0->next=p;
p->next=NULL;
}
}
}
list(top);
}
else{
if((ftell(pf)/sizeof(struct achieve))==1){
p=(struct achieve *)malloc(sizeof(struct achieve));
fread(p,sizeof(struct achieve),1,pf);
p->next=NULL;
list(p);} //此处写上输出函数}
else printf("文件里没有任何信息\n");
}}
void list (struct achieve *p){//这个是输出函数
while(p!=NULL){
printf("学号为%d 姓名为%s 成绩分别为%d %d %d %d %d %d\n",p->num,p->name,p->score[0],p->score[1],p->score[2],p->score[3],p->score[4],p->score[5]);
p=p->next;
}
}
fwrite(p,sizeof(struct achieve),1,pf);
结构文件里面的数据全错了..... 如下,求助!!!!
gdg 烫烫烫烫烫烫烫烫? 4 ? ? 烫烫烫烫烫烫