当前位置:网站首页>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;
}边栏推荐
- 8VC Venture Cup 2017 - Final Round C. Nikita and stack
- 读书笔记:《过程咨询 III》
- Boot indicator monitoring
- System table SQLite of SQLite database_ master
- Selection of database paradigm and main code
- Soft test preparation multimedia system
- Database SQL statement writing
- 【Kubernetes】Kubernetes 原理剖析与实战应用(更新中)
- 品达通用权限系统(Day 1~Day 2)
- 转:苹果CEO库克:伟大的想法来自不断拒绝接受现状
猜你喜欢

商品秒杀系统

黑客用机器学习发动攻击的九种方法

IK word breaker

Decompilation of zero time technology smart contract security series articles

Commodity seckill system

9. Intelligent transportation project (2)

Clion compiling catkin_ WS (short for ROS workspace package) loads cmakelists Txt problems

Preliminary analysis of serial port printing and stack for arm bare board debugging

The successfully resolved idea cannot use the log normally after referencing Lombok's @slf4j

爬取豆瓣读书Top250,导入sqlist数据库(或excel表格)中
随机推荐
Create a time blocker yourself
转:苹果CEO库克:伟大的想法来自不断拒绝接受现状
Clion compiling catkin_ WS (short for ROS workspace package) loads cmakelists Txt problems
知識點總結
微服务版单点登陆系统(SSO)
[kubernetes] kubernetes principle analysis and practical application (under update)
Boot的单元测试
Database SQL statement writing
Reading notes: process consulting III
Filebeat安装及使用
Basic and necessary common plug-ins of vscade
ISO documents
Boot指标监测
限流设计及实现
Deep learning: numpy
Record of user behavior log in SSO microservice Engineering
Several delete operations in SQL
最小生成树、最短路径、拓扑排序、关键路径
微信小程序 uniapp 左滑 删除 带删除icon
项目实战六:分布式事务-Seata