文件无法读入,调试时需要设置文件路径 ,不会是设置,不知道出现这种情况该怎么办,求支招!!!
程序代码:
好像是fscanf那里出错了,调试时出现find source;please enter the path for fscanf.c 不知道怎么办,怎么进入为fscanf.c设置的路径 #include<stdio.h> #include<malloc.h> #include<string.h> #include<stdlib.h> #define NULL 0 struct student { int num; char name[10]; float score[3]; struct student *next; }; typedef struct student stu; void main() { stu *creat(int a);//创建节点数为a的链表; stu *paixu(stu *head); void print(stu *head);//输出链表 stu *head;int n=4,del_num=1; head=creat(n); head=paixu(head); print(head); } stu *creat(int a)//创建节点数为a的链表; { FILE *fp; stu *head,*p,*q;int n=0; p=q=(stu*)malloc(sizeof(stu)); fp=fopen("E:\\1.txt","w"); if(fp=NULL) { printf("******找不到文件*********\n"); exit(0); } printf("******输入学生信息*********\n"); fscanf(fp,"%d%s%f%f%f",&p->num,p->name,&p->score[0],&p->score[1],&p->score[2]); head=NULL; while(n<a) { n++; if(n==1) head=p; else q->next=p; q=p; p=(stu*)malloc(sizeof(stu)); printf("******输入学生信息*********\n"); fscanf(fp,"%d%s%f%f%f",&p->num,p->name,&p->score[0],&p->score[1],&p->score[2]); } fclose(fp); q->next=NULL; return head; } void print(stu *head)//输出链表 { FILE *fp; stu *p; p=head; fp=fopen("E:\\2.txt","r"); if(fp=NULL) { printf("******找不到文件*********\n"); exit(0); } printf("******输出链表*********\n"); while(p!=NULL) { fprintf(fp," num=%d name=%s score[0]=%f score[1]=%f score[2]=%f next=%d\n",p->num,p->name,p->score[0],p->score[1],p->score[2],p->next); p=p->next; } printf("******输出结束*********\n"); fclose(fp); } //链表排序,keyword为num; stu *paixu(stu *head) { stu *p,*t,*r,*head1; if(head==NULL) return 0; head1=(stu*)malloc(sizeof(stu)); p=head;t=r=head1; t->num=p->num; strcpy(t->name,p->name); t->score[0]=p->score[0]; t->score[1]=p->score[1]; t->score[2]=p->score[2]; t->next=NULL; p=p->next; while(p!=NULL) { while(t->num<p->num&&t!=NULL) { r=t;t=t->next;} if(t==head1) { head1=p;p->next=t; } if(t==NULL) { t->next=p;p->next=NULL; } else { r->next=p;p->next=t; } p=p->next; } return head1; }