当前位置:网站首页>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;
}边栏推荐
- On the escape of inequality value
- 链游开发成品源码 链游系统开发详情说明
- The cross compilation environment appears So link file not found problem
- The king of Internet of things protocol: mqtt
- Insert string B into string A. how many insertion methods can make the new string a palindrome string
- Project practice 4: user login and token access verification (reids+jwt)
- 读书笔记:《过程咨询 III》
- The eigen library calculates the angle between two vectors
- 为什么我不推荐去SAP培训机构参加培训?
- (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
猜你喜欢
随机推荐
Record of user behavior log in SSO microservice Engineering
Request method 'POST' not supported
Invocation failed Unexpected end of file from server
Project practice 5: build elk log collection system
wm_ Concat() and group_ Concat() function
Enter n integers and output the number of occurrences greater than or equal to half the length of the array
Insert string B into string A. how many insertion methods can make the new string a palindrome string
On the escape of inequality value
数据库SQL语句撰写
Micro service single sign on system (SSO)
Minimum spanning tree, shortest path, topology sorting, critical path
ISO documents
Do you know how to compare two objects
When does the mobile phone video roll off?
Example of using QPushButton style (and method of adding drop-down menu to button SetMenu)
最小生成树、最短路径、拓扑排序、关键路径
为什么我不推荐去SAP培训机构参加培训?
品达通用权限系统(Day 1~Day 2)
Summary of several common UML diagrams
Kubernetes resource topology aware scheduling optimization









