实在是看不明白。。。。。。。
这个是老师给我发的一个代码 但是我实在是看不明白。哪位大哥来帮忙看下呗 解释下是啥意思~#include "common.h"
void main()
{
FILE *fp = NULL;
struct student TmpS;
char DataFile[40] = "";
int count = 1; /*Circular variable is to control maximum of input data.*/
printf("\nplease input the file name to store data,end with enter.");
printf("\n(Notice:Name of file can't exceed 8 characters,\nsuffix can't exceed 3 characters)\n");
scanf("%s",DataFile);
while(DataFile[0] == ('\0'))
{
printf("\nplease input new file name to store data,end with enter.");
printf("\n(Notice:Name of file can't exceed 8 characters,\nsuffix can't exceed 3 characters,\npart of exceed will be discarded.)\n");
scanf("%s",DataFile);
}
fp = fopen(DataFile,"wb+");
if (fp == NULL)
{
printf("\n Open file %s fail!End with any key.\n",DataFile);
return;
}
printf("Please input student infomation.\n0 means end.\n");
printf("(Notice:Number is not exceed 9 figures;Name is not exceed 20 characters;Range of grade:0~100)\n");
while(count <= SIZE) /* It's to control recorders less then maximum of stated input data. */
{
printf("\n Student number:");
scanf("%d",&TmpS.number);
if (TmpS.number == 0 )
break;
printf("Student name:");
scanf("%s",TmpS.name);
printf("Englishscore:");
scanf("%d",&TmpS.score);
printf("\n");
if(fwrite(&TmpS,sizeof(LENGTH),1,fp)!=1)
{
printf("\nwrite file %s fail!End with any key\n",DataFile);
return;
}
count++;
}
if (count>SIZE)
printf("\nsorry,number of data can not exceed %d\n",SIZE);
fclose(fp);
/*====Showing content of file on screen.====*/
printf("The data has stored successfully in file %s.\n",DataFile);
printf("Content as follow:\n");
fp=fopen(DataFile,"rb");
if (fp == NULL)
{
printf("\nOpen file%sfail!End with any key \n",DataFile);
return;
}
while(fread(&TmpS,sizeof(LENGTH),1,fp) != (int)NULL)
{
printf("\n%9ld\t%s\t%8d\n",TmpS.number,TmpS.name,TmpS.score);
}
fclose(fp);
}