一、填空題:
程序通過定義學(xué)生結(jié)構(gòu)體變量,存儲了學(xué)生的學(xué)號、姓名和3門課的成績。所有學(xué)生數(shù)據(jù)均以二進(jìn)制方式輸出到文件中。函數(shù)fun的功能是重寫形參filename所指文件中最后一個學(xué)生的數(shù)據(jù),即用新的學(xué)生數(shù)據(jù)覆蓋該學(xué)生原來的數(shù)據(jù),其它學(xué)生的數(shù)據(jù)不變。
請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除, 使程序得出正確的結(jié)果。
注意:源程序存放在考生文件夾下BLANK1.C中。
不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
給定源程序:
#include
#define N 5
typedef struct student {
long sno;
char name[10];
float score[3];
} STU;
void fun(char *filename, STU n)
{FILE *fp;
/**********found**********/
fp = fopen(__1__, "rb+");
/**********found**********/
fseek(__2__, -(long)sizeof(STU), SEEK_END);
/**********found**********/
fwrite(&n, sizeof(STU), 1, __3__);
fclose(fp);
}
main()
{STU t[N]={ {10001,"MaChao", 91, 92, 77}, {10002, "CaoKai", 75, 60, 88},{10003,"LiSi", 85, 70, 78}, {10004, "FangFang", 90, 82, 87},{10005,"ZhangSan", 95, 80, 88}};
STU n={10006,"ZhaoSi", 55, 70, 68}, ss[N];
int i,j; FILE *fp;
fp = fopen("student.dat", "wb");
fwrite(t, sizeof(STU), N, fp);
fclose(fp);
fp = fopen("student.dat", "rb");
fread(ss, sizeof(STU), N, fp);
fclose(fp);
printf("\nThe original data :\n\n");
for (j=0; j
{printf("\nNo: %ld Name: %-8s Scores: ",ss[j].sno, ss[j].name);
for (i=0; i<3; i++) printf("%6.2f ", ss[j].score[i]);
printf("\n");
}
fun("student.dat", n);
printf("\nThe data after modifing :\n\n");
fp = fopen("student.dat", "rb");
fread(ss, sizeof(STU), N, fp);
fclose(fp);
for (j=0; j
{printf("\nNo: %ld Name: %-8s Scores: ",ss[j].sno, ss[j].name);
for (i=0; i<3; i++) printf("%6.2f ", ss[j].score[i]);
printf("\n");
}
}
解題答案:
/**********第一空**********/
fp = fopen(filename, "rb+");
/**********第二空**********/
fseek(fp, -(long)sizeof(STU), SEEK_END);
/**********第三空**********/
fwrite(&n, sizeof(STU), 1, fp);
2021-07-09
2021-07-08
2021-07-08
2021-07-08
2021-07-08
2021-07-08
2021-07-07
2021-07-07
2021-07-07
2021-07-07
2021-07-07
2021-07-06
2021-07-06
2021-07-06
工作態(tài)度怎么寫 具有穩(wěn)定的工作心態(tài)
2021-07-06
該文觀點(diǎn)僅代表作者本人,查查吧平臺系信息發(fā)布平臺,僅提供信息存儲空間服務(wù),不承擔(dān)相關(guān)法律責(zé)任。圖片涉及侵權(quán)行為,請發(fā)送郵件至85868317@qq.com舉報,一經(jīng)查實(shí),本站將立刻刪除。