exam12-12.cpp

来自「很好的C程序设计教程」· C++ 代码 · 共 29 行

CPP
29
字号
/*文件名:exam12_12.cpp*/
#include <stdio.h>
main()
{
	FILE *fp;
	struct student 
	{
		char name[10];
		int score;
	} stud;
	int i=0;
	if ((fp=fopen("stud.bin","rb"))==NULL) 
	{
		printf("不能读取stud.bin文件\n");
		return;
	}
	printf("姓名   成绩\n");
	printf("----------\n");
	while (1) 
	{
		fread(&stud,sizeof(struct student),1,fp);
		if (feof(fp)) break;
			if (stud.score>=80)
				printf("%s   %d\n",stud.name,stud.score);
		i++;
	}
     fclose(fp);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?