⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 correctfile.cpp

📁 初学者很好的练习的实例
💻 CPP
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 4

struct student_type
{
	char name[10];
	int num;
	int age;
} stud[SIZE];

void main()
{
	int i;
	FILE *fp;
	fp=fopen("c:\\stu_list","r+");
	if(fp==NULL)
	{
		printf("\n 打开文件失败!");
		exit(1);
	}
	for(i=0;i<SIZE;i++)
	{
		fread(&stud[i],sizeof(struct student_type),1,fp);
		if(strcmp(stud[i].name,"fun")==0)
		{
			stud[i].age = 50;
			printf("%-10s,%4d,%4d\n",stud[i].name,stud[i].num,stud[i].age);
			fp=fopen("c:\\stu_list","r+");
			fseek(fp,i*sizeof(struct student_type),0);
			fwrite(&stud[i],sizeof(struct student_type),1,fp);
			fseek(fp,(i+1)*sizeof(struct student_type),0);
		}
	}
	fclose(fp);
}

⌨️ 快捷键说明

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