📄 correctfile.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 + -