首页 > 其他 > 详细

fseek 用法

时间:2021-09-09 00:30:54      阅读:53      评论:0      收藏:0      [点我收藏+]

#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#pragma warning(disable : 4996)


struct Student
{
char name[20];
int num;
int age;
float scor;
};
int main()
{
//fscanf,fprintf,从硬盘上读取文件,和scanf printf差不多,后者是从显示器上读取文件

//fseek 用法
struct Student boys[3];
struct Student boy;
struct Student *pBoys;
FILE *fp;

pBoys = boys;
fp = fopen("test.txt", "wb+");
if (fp == NULL)
{
puts("不能打开该文件\n");
getch();
exit(0);
}
printf("请输入学生的相关数据\n");
for (size_t i = 0; i < 3; i++)
{
scanf("%s %d %d %f",&pBoys->name,&pBoys->num,&pBoys->age,&pBoys->scor);
pBoys++;
}
fwrite(boys, sizeof(struct Student), 3, fp);
fseek(fp, sizeof(struct Student), SEEK_SET);

fread(&boy, sizeof(struct Student), 1, fp);//读取第二个学生的信息
printf("%s %d %d %f", boy.name, boy.age, boy.age, boy.scor);
fclose(fp);

 

 

 

 


return 0;
}

fseek 用法

原文:https://www.cnblogs.com/wang-xiao-shuai/p/15241435.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!