下列给定程序的功能是调用fun函数建立班级通讯录。通讯录中记录每位学生的编号、姓名和电话号码。班级人数和学生信息从键盘读入,每个人的信息作为一个数据块写到名为myfile5.dat的二进制文件中。 #include #include #define N 5 typedef struct { int num; char name[10]; char tel[10]; }STYPE; void check(); int fun(STYPE *std) { /**********found**********/ ______ *fp; int i; if((fp=fopen("myfile5.dat","wb"))==NULL) return(0); printf("\nOutput data to file !\n"); for(i=0; i fwrite(&std[i], sizeof(STYPE), 1, fp); 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); }