这个模板看不懂,求解!真的着急
#include<stdio.h>#include<string.h>
struct students //定义一个结构体struct students;
{
int xuehao;
char names[10];
float chengji;
};
int READCJB(struct students*chengjibiao) //这句有什么用??什么意思???
{
int count;
FILE*fp=NULL;
if(NULL==(fp=fopen("c:\\cjb.dat","a+"))) //a+为读写打开一个文本文件;
{
return -1;
}
int len;
fseek(fp,0L,SEEK_END); //将位置指针从文件末尾向后退0个字节;
len=ftell(fp); //ftell:得到文件位置指针的当前值;
if(len!=0)
{
fseek(fp,0L,SEEK_SET);
fread(&count,4,1,fp); //为什么要读4个字节数???为什么要进行1个size字节的数据项???
fread(chengjibiao,sizeof(struct students),count,fp);
printf("成绩表录入完成。\n");
}
fclose(fp);
return count;
}
bool WRITECJB(struct students*chengjibiao,int count) //bool是什么东西???
{
FILE*fp=NULL;
if(NULL==(fp=fopen("c:\\cjb.dat","a+")))
{
return false;
}
fseek(fp,0L,SEEK_SET); //将位置指针从文件末尾向后退0个字节;
fwrite(&count,4,1,fp);
fwrite(chengjibiao,sizeof(struct students),count,fp);
fclose(fp);
return true;
}
main()
{
struct students stu[20]; //这句是什么意思,有什么用????
int numofstudents=0;
int numofsearch=0;
int i=0;
char numofsearchxuehao[20];
numofsearch=READCJB(stu); //这句什么意思???
while(true)
{
char input[100];
gets(input);
if(strcmp(input,"LR")==0)
{
printf("请输入所要录入的学生数,不超过20名\n");
scanf("%d",&numofstudents);
for(i=0;i<numofstudents;i++)
{
stu[i].xuehao=i+1;
printf("请输入学生的姓名:\n");
scanf("%s",stu[i].names);
printf("请输入学生的成绩:\n");
scanf("%f",&(stu[i].chengji));
}
printf("录入完成。\n");
}
else if(strcmp(input,"CZ")==0)
{
printf("请输入要查找的学生数量,不超过20名\n");
scanf("%d",&numofsearch);
for(i=0;i<numofsearch;i++)
{
printf("请输入所要查找的学生的学号:\n");
scanf("%d",&(numofsearchxuehao[i]));
}
printf("查找完成\n");
}
else if(strcmp(input,"DY")==0)
{
printf("-----------------------------------------------------\n");
printf("学号 姓名 成绩\n");
for(i=0;i<numofsearch;i++)
{
printf("%d %30s %30f\n",stu[(numofsearchxuehao[i])-1].xuehao,stu[(numofsearchxuehao[i])-1].names,stu[(numofsearchxuehao[i])-1].chengji);
}
}
else if(strcmp(input,"EXIT")==0)
{
break;
}
}
WRITECJB(stu,numofstudents);
return 0;
}