各位大哥,请问我这个是哪里错了,还有就是main函数那里应该怎么写?
#include <stdio.h>struct student
{
int num;
char name[20];
float score1; /*高数成绩*/
float creh1; /*高数学分*/
float score2; /*英语成绩*/
float creh2; /*英语学分*/
float score3; /*物理成绩*/
float creh3; /*物理学分*/
};
struct student stu[10] ={{0101,”xiaozhang”,81.5,3.15,80,3.0,89.0,3.9},{0102,xiaoli”,62.0,1.2,90.0,4.0,65.,1.55},{0103,”xiaowang”,77.5,2.75,83.5,3.35,79.0,2.9},{0104,”xiaozhou”,96.0,4.6,62.0,1.2,93.0,4.3},{0105,”xiaoliu”,55.0,0,81.0,3.1,56.0,0},{0201,”xiaohu”,42.0,0,65.0,1.5,56.5,0},{0202,”xiaozhao”,69.0,1.9,86.0,3.6,65.0,1.5},{0301,”xiaohe”,80.0,3.0,70.0,2.0,67.0,1.7},{0302,”xiaohuang”,60.0,1,77.0,2.7,85.0,3.5},{0303,””,56.0,.0,86.0,3.6,55.0,0}};
/****************************************************************************/
void menu() /*主菜单界面*/
{
int n,wl;
do
{
printf(“\t\t********************************************\n\n”);
printf(“\t\t********************************************\n\n”);
printf(“\t\t ***choose function*********************\n\n”);
printf(“\t\t ***1 search**********************\n\n”);
ptintf(“\t\t ***2 backupdata************************\n\n”);
printf(“\t\t ***3 exit**********************\n\n”);
printf(“\t\t********************************************\n\n”);
printf(“\t\t********************************************\n\n”);
printf(“please choose nuber(1or2):[ ]\b\b”);
scanf(“%d”,&n);
if(n<1||n>3)
wl=1;
else wl=0;
}
while(wl==1)
switch(n)
{
case 1:fun();break;
case 2:backupdata();break;
}
}
/*******************************************************************/
void fun()
{
FILE *fp;
if((fp=fopen(“C:\\c\\score”,”wb”))==NULL)
{printf(“can not open file\n”);
exit(0);
}
struct student *p;
for(p=stu;p<stu+10;p++)
{if(creh1!=0&& creh2!=0&& creh3!=0) /*三科成绩都及格*/
{printf(“%-20s has pass!\n”,p->name);
if(fwrite(stu,sizeof(struct student),1,fp))!=1) /*吧及格的同学的数据存入score.txt文件中*/
{printf(“file write error\n”);
fclose(fp);
}
}
}
}
/**********************************************************************/
void backupdata()
{int i;
FILE *fp1,*fp2;
if ((fp1=fopen(“C:\\c\\student”,”rb”))==NULL)
{printf(“can not open file1\n”);
exit(0);
}
if((fp2=fopen(“C:\\c\\backup”,”wb”))==NULL)
{printf(“can not open file2\n”);
exit(0);
}
for(i=0;i<10;i++)
{fseek(fp1,i*sizeof(struct student),0);
fread(&stu[1],sizeof(struct student),1,fp1);
fwrite(&stu[1],sizeof(struct student),1,fp2); /*将文件student.txt中的信息保存到文件backup.txt中*/
fclose(fp1);
fclose(fp2);
}
}
/*****************************************************************************/
void main()
{
menu();
}
[[it] 本帖最后由 saysaysay 于 2008-6-24 21:50 编辑 [/it]]