当前位置:网站首页>fopen、fwrite、fseek、ftell、fread使用demo
fopen、fwrite、fseek、ftell、fread使用demo
2022-07-24 06:56:00 【鸡蛋炒肉】
#include <stdio.h>
#include <stdlib.h>
#include <string.h>int main() {
int ret = 0;
char buf[] = “mr liu yyds”;
char readbuf[128] = {0};
FILE *fp;
fp = fopen(“fopen.txt”, “w+”);
if (NULL == fp)
{
printf(“fopen fail\n”);
return 0;
}
if (1 != fwrite(buf, strlen(buf), 1, fp))//fputc fputs
{
printf(“fwrite fail\n”); goto error;
}
if (fseek(fp, 0, SEEK_END))
{
printf(“fseek fail\n”); goto error;
}
ret = ftell(fp);
if (!ret)
{
printf(“ftell fail\n”); goto error;
}
fseek(fp, 0, SEEK_SET);
if (0 == fread(readbuf, ret, 1, fp))
{
printf(“fread fail\n”); goto error;
}
printf(“readbuf[%s]\n”, readbuf); error:
fclose(fp);
return 0; }
边栏推荐
- Aggregated new ecological model - sharing purchase, membership and reward system
- 文件上传下载Demo
- yocs_ velocity_ Smooth source code compilation
- C language from entry to soil (III)
- Raspberry pie change source
- Job search memo
- [tips] a simple method to create a version control project
- /etc/rc. Local setting UI program startup and self startup
- Upload pictures Base64
- Upload excel file
猜你喜欢

17. 什么情况用ArrayList or LinkedList呢?

Flow control statement of avascript

MongoDB应用场景及选型(海量数据存储选型)

Paper reading: hardnet: a low memory traffic network

Redis persistence

Part II - C language improvement_ 3. Pointer reinforcement

Chapter007-FPGA学习之IIC总线EEPROM读取

我的创作纪念日

Vs debugging

Decompress the anchor and enjoy 4000w+ playback, adding a new wind to the Kwai food track?
随机推荐
项目上线就炸,这谁受得了
QoS服务质量四QoS边界行为之流量监管
File "manage.py", line 14) from exc ^ syntaxerror: cause and solution of invalid syntax error
重磅直播 | ORB-SLAM3系列代码讲解地图点(专题二)
【Word】如何生成左侧的索引目录
Part II - C language improvement_ 1. Overview of C language
File upload and download demo
C process running permission
Part II - C language improvement_ 3. Pointer reinforcement
Redis master-slave mechanism
Compilation and debugging (GCC, g++, GDB)
Raspberry pie change source
FPGA realizes reading and writing of axi4 bus
C language from introduction to soil -- super detailed summary of operators
第二部分—C语言提高篇_2. 内存分区
Chinese manufacturers may catch up with the humanoid robot Optimus "Optimus Prime", which has been highly hyped by musk
【LeetCode】444. 序列重建
安全工具之hackingtool
上传excel文件
[sequential logic circuit] - register