注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
#define N 5
typedef struct
{int num;
char name[10];
char tel[10];
}STYPE;
void check();
/**********found**********/
int fun(___1___ *std)
{
/**********found**********/
___2___ *fp; int i;
if((fp=fopen("myfile5.dat","wb"))==NULL)
return(0);
printf("\nOutput data to file !\n");
for(i=0; i
/**********found**********/
fwrite(&std[i], sizeof(STYPE), 1, ___3___);
fclose(fp);
return (1);
}
main()
{STYPE s[10]={ {1,"aaaaa","111111"},{1,"bbbbb", "222222"},{1,"ccccc","333333"},{1,"ddddd","444444"},{1,"eeeee", "555555"}};
int k;
k=fun(s);
if (k==1)
{printf("Succeed!"); check();}
else
printf("Fail!");
}
void check()
{FILE *fp; int i;
STYPE s[10];
if((fp=fopen("myfile5.dat","rb"))==NULL)
{printf("Fail !!\n"); exit(0);}
printf("\nRead file and output to screen :\n");
printf("\n num name tel\n");
for(i=0; i
{fread(&s[i],sizeof(STYPE),1, fp);
printf("%6d %s %s\n",s[i].num, s[i].name,s[i].tel);
}
fclose(fp);
}
解题答案:
/**********第一空**********/
int fun(STYPE *std)
/**********第二空**********/
FILE *fp; int i;
/**********第三空**********/
fwrite(&std[i], sizeof(STYPE), 1, fp);
******************************************
相关推荐: