C语言新手求助.....要交作业啦...555
#include"stdio.h"#include<string.h>
#include<stdlib.h>
#define N 30
struct student
{
int num;
char name[20];
float chinese;
float maths;
float english;
float average;
float sum;
}stu[N];
menu()
{
int a;
char n;
do
{
printf("\n\t\t\t **********MENU**********\n");
printf("\t\t\t\tA.Input a new data\n");
printf("\t\t\t\tB.Browse all data\n");
printf("\t\t\t\tC.Search data\n");
printf("\t\t\t\tD.Order by sum\n");
printf("\t\t\t\tE.Addition data\n");
printf("\t\t\t\tF.Exit the system\n");
printf("\n\t\t\t ************************");
printf("\n Choose a number you want(A~F):");
n=getchar();
if(n<'A'||n>'F')
{
a=1;
printf("please choose the correct number(A~f)");
}
else
a=0;
}
while (a==1);
switch(n)
{
case 'A':input();break;
case 'B':browse();break;
case 'C':search();break;
case 'D':order();break;
case 'E':add();break;
case 'F':exit(0);
}
}
save(int n)
{
FILE *fp;
int i;
if((fp=fopen("score.txt","wb"))==NULL)
{printf("\nCannot open file\n");
return NULL;
}
for(i=0;i<n;i++)
if(stu[i].sum!=0)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
load()
{
FILE *fp;
int i;
if((fp=fopen("score.txt","rb"))==NULL)
{printf("\nCannot open file\n");
return NULL;
}
for(i=0;!feof(fp);i++)
fread(&stu[i],sizeof(struct student),1,fp);
fclose(fp);
return(i-1);
}
input()
{ int a,i,n;
printf("How many students do you want to input?(1~N)");
scanf("%d",&a);
for(i=0;i<a;i++)
{
printf("Please input the %d student's data\n",i+1);
printf("the nunber:");
scanf("%d",stu[i].num);
printf("Name:");
scanf("%s",stu[i].name);
printf("Chinese:");
scanf("%f",stu[i].chinese);
printf("Maths:");
scanf("%f",stu[i].maths);
printf("English:");
scanf("%f",stu[i].english);
stu[i].sum=stu[i].chinese+stu[i].maths+stu[i].english;
stu[i].average=stu[i].sum/3;
}
if(i!=0) save(n);
choose();
}
browse()
{
int i,j,n;
n=load();
printf("\n number name Chinese Maths English Average Sum\n");
for(i=0;i<n;i++)
printf("%d %s %d %d %d %d\n",stu[i].num,stu[i].name,stu[i].chinese,stu[i].maths,stu[i].english,stu[i].average,stu[i].sum);
system("pause");
menu();
}
order()
{
int i,j,k,n;
struct student s;
n=load();
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
if(stu[j].sum<stu[k].sum) k=j;
s=stu[i];
stu[i]=stu[k];
stu[k]=s;
}
save(n);
choose();
}
add()
{
int i,n,m,k;
FILE *fp;
n=load();
printf("How many students are you want to add(1~%d)?:",N-n);
scanf("%d",&m);
k=m+n;
for(i=n;i<k;i++)
{
printf("\n Please input the %d student's data\n",i+1);
printf("the nunber:");
scanf("%d",stu[i].num);
printf("Name:");
scanf("%s",stu[i].name);
printf("Chinese:");
scanf("%d",stu[i].chinese);
printf("Maths:");
scanf("%d",stu[i].maths);
printf("English:");
scanf("%d",stu[i].english);
stu[i].sum=stu[i].chinese+stu[i].maths+stu[i].english;
stu[i].average=stu[i].sum/3;
}
if((fp=fopen("score.txt","ab"))==NULL)
{printf("Cannot open file.\n");
}
for(i=n;i<k;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error.\n");
fclose(fp);
choose();
}
search()
{
int a,i,n;
n=load();
printf("\nWhich number do you want to find? :");
scanf("%d",&a);
for(i=0;i<n;i++)
{
if(stu[i].num==a)
printf("\n number name Chinese Maths English Average Sum\n");
printf("%d %s %d %d %d %d\n",stu[i].num,stu[i].name,stu[i].chinese,stu[i].maths,stu[i].english,stu[i].average,stu[i].sum);
}
choose();
}
choose()
{
int a;
print("\nWhat do you want to do?\n1.Browse all\n2.Back:");
scanf("%d",&a);
if(a==1) brows();
else menu();
}
main()
{
menu();
}
各位好...这个我写的一个程序...
但是为什么在编译的时候wintc就说我错误...未定义符号'_print'在模块...和未定义符号'_brows'在模块...
求救吖....