struct Students
{
char name[20];
unsigned int num;
unsigned int markOfCh;
unsigned int markOfMa;
unsigned int markOfEn;
struct Students *next;
};
typedef struct Students Ss;
Ss * ReadFromFile() /*从文件中读出数据,存入链表*/
{
char filename[20],*pn,n;
unsigned int *pm,i;
Ss *p,*pr,*head;
FILE *fp;
head=(Ss *)malloc(sizeof(Ss));
pr=head;
p=pr->next;
printf("\nenter the filename please:");
scanf("%s",filename);
fp=fopen(filename,"r");
while(feof(fp)==0)
{
fscanf(fp,"%s",p->name);
fscanf(fp,"%d",p->num);
fscanf(fp,"%d",p->markOfCh);
fscanf(fp,"%d",p->markOfMa);
fscanf(fp,"%d",p->markOfEn);
p=(Ss *)malloc(sizeof(Ss));
pr->next=p;
pr=pr->next;
}
p->next=NULL;
return (head);
}
void SaveToFile(Ss *head) /*把链表存入文件中*/
{
char c,filename[20],*pr;
unsigned int *pm;
Ss *p=head;
FILE *fp;
printf("\nenter the filename please:");
scanf("%s",filename);
fp=fopen(filename,"w");
do
{
p=p->next;
fprintf(fp,"%s",p->name);
fprintf(fp,"%c",'\r');
fprintf(fp,"%d",p->num);
fprintf(fp,"%c",'\r');
fprintf(fp,"%d",p->markOfCh);
fprintf(fp,"%c",'\r');
fprintf(fp,"%d",p->markOfMa);
fprintf(fp,"%c",'\r');
fprintf(fp,"%d",p->markOfEn);
fprintf(fp,"%c",'\r');
}while(p->next!=NULL);
}
本人初学者 ,对文件一点都不懂,请各高手指教
为什么用上面的ReadFromFile函数读不了SaveToFile写的文件呢?
(写函数的功能可以实现)
帮忙修改 下 谢了!