填空题
下列给定程序的功能是调用fun函数建立班级通信录。通信录中记录每位学生的编号、姓名和电话号码。班级人数和学生信息从键盘读入,每个人的信息作为一个数据块写到名为myfile5.dat的二进制文件中。
请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<stdlib.h>
#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<N; 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 hum name tel/n");
for(i=0; i<N; i++)
{fread(&s[i], sizeof(STYPE), 1, fp);
printf("%6d %s% s/n", s[i].num, s[i].name, s[i].tel);
}
fclose(fp);
}