当前位置: 首页 > java >正文

c语言之fprintf函数和ftell的使用

fprintf函数作用:将输出写入到给定的输出流中.
ftell函数作用:ftell() 函数是 C 语言标准库 <stdio.h> 中的一个函数,其作用是获取由 stream 所指向的文件流的文件位置指示器的当前值.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>int main()
{//  int fprintf(FILE *stream, const char *format, ...);//write output to the given output  streamchar name[64] = {0}; char hexnumber[10] = {0x01,0x02,0x03};FILE *file;strcat(name, "rgba555");file = fopen(name, "w");  // 若存在必回擦掉原有内容从头写if (file == NULL) {printf("open %s failed\n", name);//goto ERROR;}//fprintf(file,"Hello %s\n", name);fprintf(file, "0x%02x ,0x%02x ,", hexnumber[0]&0xff, hexnumber[1]&0xff);fprintf(file, "};\n");fclose(file);
}

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>int main()
{FILE*fp;int len;fp = fopen("file.txt","r");if( fp == NULL ) {perror ("打开文件错误");return(-1);}fseek(fp,0,SEEK_END);// The ftell() function obtains the current value of the file position indicator for the stream pointed to by streamlen = ftell(fp);fclose(fp);printf("file.txt的总大小=%d字节\n",len);return 0;
}

http://www.xdnf.cn/news/1058.html

相关文章:

  • 基于 Vue,使用Vuex 或事件总线实现跨组件通信
  • 高并发场景下的淘宝 API 开发实践:商品数据实时采集与性能优化
  • 迅为RK3568开发板内核模块实现-设置交叉编译器
  • 基于mybatis与PageHelper插件实现条件分页查询(3.19)
  • Linux学习笔记|入门指令
  • 维度建模工具箱 提纲与总结
  • #Paper Reading# DeepSeek-V3
  • docker部署seata
  • Nebula图数据库
  • STM32H5开发陀螺仪LSM6DSV16X(1)----轮询获取陀螺仪数据
  • 【leetcode题解】滑动窗口
  • 【瑞萨RA4L1-SENSOR套件测评】LCD 显示
  • 2025年pta团队设计天梯赛题解
  • FreeRTOS互斥信号量解决优先级翻转实战教程
  • docker 中将dpo后的模型转为ollama能够调用的gguf格式
  • 通过Docker Desktop配置OpenGauss数据库的方法(详细版+图文结合)
  • 助conda命令把环境导出为一个文件,然后在 Linux 系统里利用该文件重新创建相同的环境
  • mapbox进阶,实现掩膜效果,并控制掩膜透明度
  • 数组的应用
  • Linux[基本指令]
  • Ubuntu20.04安装Pangolin遇到的几种报错的解决方案
  • 【项目中的流程管理(九)】
  • 关于 LangChain Execution Language (LCEL) 的详细解释,涵盖其核心概念、语法、应用场景及示例
  • C++ GPU并行计算开发实战:利用CUDA/OpenCL加速粒子系统与流体模拟
  • 探究CF1009(div3)C题——XOR and Triangle
  • 宝塔面板引发的血案:onlyoffice协作空间无法正常安装的案例分享
  • 深入了解 WebGIS 系统:构建地理空间信息的网络桥梁
  • C语言高频面试题——strcpy与memcpy区别
  • mcp server、client和本地大模型集成调用
  • Argo CD