当前位置:网站首页>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;
}边栏推荐
- Kubernetes resource topology aware scheduling optimization
- Tag dynamic programming - preliminary knowledge for question brushing -2 0-1 knapsack theory foundation and two-dimensional array solution template
- Boot指标监测
- NFTGameFi链游系统开发详解方案丨链游系统开发原理解析
- Successfully solved the problem of garbled microservice @value obtaining configuration file
- Button how to dynamically set drawablebottom (setcomposunddrawables is invalid)
- (树) 树状数组
- Why don't I recommend going to sap training institution for training?
- 抖音实战~首页视频~下拉刷新
- 项目实战五:搭建ELk日志收集系统
猜你喜欢
随机推荐
WebView load pdf
Feign remote call
Nftgamefi chain game system development detailed solution - chain game system development principle analysis
字符串String转换为jsonArray并解析
Current limiting design and Implementation
Jsonutils tool class (based on Alibaba fastjson)
抖音实战~搜索页面~视频详情
爬取豆瓣读书Top250,导入sqlist数据库(或excel表格)中
NFTGameFi链游系统开发详解方案丨链游系统开发原理解析
(树) 树状数组
转:苹果CEO库克:伟大的想法来自不断拒绝接受现状
抖音实战~分享模块~生成短视频二维码
Minimum spanning tree, shortest path, topology sorting, critical path
Do you know how to compare two objects
50 lines of code to crawl TOP500 books and import TXT documents
Basic and necessary common plug-ins of vscade
股票开户的具体步骤是什么?网上开户安全吗?
String string is converted to jsonarray and parsed
Leetcode 128 longest continuous sequence
Pinda general permission system (day 1~day 2)









