为什么插入模块一的程序后整个程序就产生错误,一旦删除模块一的程序就能运行呢?请高手修改一下,并说说原因,谢谢!
#include "stdio.h"
#define SIZE 50
struct student
{ int n;
int num;
int age;
char addr[10];
char name[10];
float score[3];
float avr;
}stu[SIZE];
/*1. Input records模块一*/
void finput()
{
FILE *fp;
int i;
fp=fopen("fstu","wb");
for(i=0;i<SIZE;i++)
{ printf("Input student's n=%d num,name,age,addr,maths,computer,english:",i+1);
scanf("%d%s%d%s%f%f%f",&stu[i].num,stu[i].name,&stu[i].age,stu[i].addr,&stu[i].score[0],
&stu[i].score[1],&stu[i].score[2] );
stu[i].avr=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3.0;
fclose(fp);
}
void fresearch()
{
}
/*3. Change the records*/
void fchange()
{
}
/*4. Append a record*/
void fappend()
{
}
/*5. List the record*/
void flist()
{ int i;
FILE *fp;
fp=fopen("fstu","rb");
clrscr();
printf(" Student's Datas \n");
printf("***************************************************************\n");
printf("* NO. num name age addr maths computer english avr *\n");
printf("***************************************************************\n");
for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++)
{ printf("%12d%71d %-10s%2d %-10s",stu[i].n,stu[i].num,stu[i].name,
stu[i].age,stu[i].addr);
printf("%3d%3d%3d%6.2f\n",stu[i].score[0],stu[i].score[1],
stu[i].score[2],stu[i].avr);
}fclose(fp);
printf("*********************************************************\n\n");
getch();
}
/*6. Sort the records*/
void fsort()
{
}
/*7. Copy the file*/
void fcopy()
{
}
/*8. Restore the file*/
void frestore()
{
}
main()
{ int n;
clrscr();
for(;;)
{ printf("*************************************************************\n");
printf("* STUDENT M I S *\n");
printf("*************************************************************\n");
printf("* 1. Input a record *\n");
printf("* 2. Research records *\n");
printf("* 3. Change the records *\n");
printf("* 4. Append a record *\n");
printf("* 5. List the records *\n");
printf("* 6. Sort the records *\n");
printf("* 7. Copy the file *\n");
printf("* 8. Restore the file *\n");
printf("*************************************************************\n");
printf("* 0. Exit the system *\n");
printf("*************************************************************\n");
printf(" Please enter (0--8): \n");
scanf("%d",&n);
switch (n)
{case 1:finput(); break;
case 2:fresearch(); break;
case 3:fchange(); break;
case 4:fappend(); break;
case 5:flist(); break;
case 6:fsort(); break;
case 7:fcopy(); break;
case 8:frestore(); break;
case 0:printf("**************************************************\n");
printf("* FINISH *\n");
printf("**************************************************\n");
printf("* GOOD BYE *\n");
printf("**************************************************\n");
exit();
default:printf("EORROR!!!Please press any key continute!\n");
}
}
getch();
}
#include "stdio.h"
#define SIZE 50
struct student
{ int n;
int num;
int age;
char addr[10];
char name[10];
float score[3];
float avr;
}stu[SIZE];
/*1. Input records模块一*/
void finput()
{
FILE *fp;
int i;
fp=fopen("fstu","wb");
for(i=0;i<SIZE;i++)
{ printf("Input student's n=%d num,name,age,addr,maths,computer,english:",i+1);
scanf("%d%s%d%s%f%f%f",&stu[i].num,stu[i].name,&stu[i].age,stu[i].addr,&stu[i].score[0],
&stu[i].score[1],&stu[i].score[2] );
stu[i].avr=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3.0;
fclose(fp);
}
void fresearch()
{
}
/*3. Change the records*/
void fchange()
{
}
/*4. Append a record*/
void fappend()
{
}
/*5. List the record*/
void flist()
{ int i;
FILE *fp;
fp=fopen("fstu","rb");
clrscr();
printf(" Student's Datas \n");
printf("***************************************************************\n");
printf("* NO. num name age addr maths computer english avr *\n");
printf("***************************************************************\n");
for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++)
{ printf("%12d%71d %-10s%2d %-10s",stu[i].n,stu[i].num,stu[i].name,
stu[i].age,stu[i].addr);
printf("%3d%3d%3d%6.2f\n",stu[i].score[0],stu[i].score[1],
stu[i].score[2],stu[i].avr);
}fclose(fp);
printf("*********************************************************\n\n");
getch();
}
/*6. Sort the records*/
void fsort()
{
}
/*7. Copy the file*/
void fcopy()
{
}
/*8. Restore the file*/
void frestore()
{
}
main()
{ int n;
clrscr();
for(;;)
{ printf("*************************************************************\n");
printf("* STUDENT M I S *\n");
printf("*************************************************************\n");
printf("* 1. Input a record *\n");
printf("* 2. Research records *\n");
printf("* 3. Change the records *\n");
printf("* 4. Append a record *\n");
printf("* 5. List the records *\n");
printf("* 6. Sort the records *\n");
printf("* 7. Copy the file *\n");
printf("* 8. Restore the file *\n");
printf("*************************************************************\n");
printf("* 0. Exit the system *\n");
printf("*************************************************************\n");
printf(" Please enter (0--8): \n");
scanf("%d",&n);
switch (n)
{case 1:finput(); break;
case 2:fresearch(); break;
case 3:fchange(); break;
case 4:fappend(); break;
case 5:flist(); break;
case 6:fsort(); break;
case 7:fcopy(); break;
case 8:frestore(); break;
case 0:printf("**************************************************\n");
printf("* FINISH *\n");
printf("**************************************************\n");
printf("* GOOD BYE *\n");
printf("**************************************************\n");
exit();
default:printf("EORROR!!!Please press any key continute!\n");
}
}
getch();
}