当前位置:网站首页>C语言 文件光标 fseek
C语言 文件光标 fseek
2022-06-26 19:11:00 【laocooon】
//按块写文件
struct Hero
{
char name[64]; //姓名
int age; //年龄
};
void test02()
{
FILE* fp = NULL;
fp = fopen("fseek.txt", "w");
if (fp == NULL)
{
printf("文件打开失败\n");
return;
}
struct Hero heros[4] = {
{ "孙悟空", 33 },
{ "韩信", 28 },
{ "赵云", 45 },
{ "亚瑟", 35 }
};
for (int i = 0; i < 4; i++)
{
//参数1 数据首地址 参数2 块大小 参数3 块数量 参数4 文件指针
fwrite(&heros[i], sizeof(struct Hero), 1, fp);
}
//关闭文件
fclose(fp);
//fseek函数 进行随机位置读取
FILE* fp2 = NULL;
fp2 = fopen("fseek.txt", "r");
if (fp2 == NULL)
{
printf("文件打开失败\n");
return;
}边栏推荐
- Selection of database paradigm and main code
- (几何) 凸包问题
- 成功解决之idea引用Lombok的@Slf4j后无法正常使用log
- 链游开发成品源码 链游系统开发详情说明
- Button how to dynamically set drawablebottom (setcomposunddrawables is invalid)
- (multi threading knowledge points that must be mastered) understand threads, create threads, common methods and properties of using threads, and the meaning of thread state and state transition
- wm_ Concat() and group_ Concat() function
- 9. Intelligent transportation project (2)
- Request method 'POST' not supported
- Database SQL statement writing
猜你喜欢
![[recommended collection] these 8 common missing value filling skills must be mastered](/img/ab/353f74ad73ca592a3f97ea478922d9.png)
[recommended collection] these 8 common missing value filling skills must be mastered

Refresh the strong pointer assignment problem in the HP-UX system of Sanguan

ARM裸板调试之串口打印及栈初步分析

Boyun, standing at the forefront of China's container industry

品达通用权限系统(Day 3~Day 4)

Convex hull problem

Crawl Douban to read top250 and import it into SqList database (or excel table)

Commodity seckill system

限流设计及实现

Filebeat安装及使用
随机推荐
【Kubernetes】Kubernetes 原理剖析与实战应用(更新中)
抖音实战~分享模块~短视频下载(保存到相册)
抖音实战~分享模块~复制短视频链接
Filebeat安装及使用
抖音实战~分享模块~生成短视频二维码
股票开户的具体步骤是什么?网上开户安全吗?
Example of using QPushButton style (and method of adding drop-down menu to button SetMenu)
uni-app使用canvas绘制二维码
Selection of database paradigm and main code
Comparing the size relationship between two objects turns out to be so fancy
Logstash安装及使用
Micro service single sign on system (SSO)
To: seek truth from facts
wm_ Concat() and group_ Concat() function
项目实战五:搭建ELk日志收集系统
The successfully resolved idea cannot use the log normally after referencing Lombok's @slf4j
几种常见的UML关系图汇总
数据库SQL语句撰写
关于不等式取值转义的思路
Successfully solved the problem of garbled microservice @value obtaining configuration file