news 2026/4/23 14:25:01

Linux基础IO

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Linux基础IO

1:C语言文件IO

C语言中的文件操作函数如下:

文件操作函数

功能

fopen

打开文件

fclose

关闭文件

fputc

写入一个字符

fgetc

读取一个字符

fputs

写入一个字符串

fgets

读取一个字符串

fprintf

格式化写入数据

fscanf

格式化读取数据

fwrite

向二进制文件写入数据

fread

从二进制文件读取数据

fseek

设置文件指针的位置

ftell

计算当前文件指针相对于起始位置的偏移量

rewind

设置文件指针到文件的起始位置

ferror

判断文件操作过程中是否发生错误

feof

判断文件指针是否读取到文件末尾

下面只会选择性对C语言的部分文件操作函数进行使用,若想详细了解其余文件操作函数的使用方法,请跳转到博主的其它博客:文件处理不再难:带你轻松攻克C语言文件操作_c语言大文件处理-CSDN博客

代码语言:javascript

AI代码解释

#include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include <stdlib.h> int main() { FILE * fp = fopen("log.txt","w"); if(NULL == fp) { perror("fopen"); exit(-1); } fclose(fp); fp = NULL; return 0; }

运行程序后,在当前路径下就会生成对应文件.

那么我们也可以通过输出重定向向文件里面写入新的内容.

1.1:对文件的初步理解

那么有了上面的简单例子我们可以对文件有一个简单的初步理解

  • 打开文件,本质是进程在打开文件.
  • 文件在没有被打开的时候,在什么地方上------->在磁盘上头.
  • 进程能够同时打开很多文件.

系统中可以存在很多进程------------>很多情况下,OS内部,一定存在大量的被打开的文件---------->那么OS就要对这些被打开的文件进行处理,先描述,再组织------->因此可以推测,每一个被打开的文件在OS内部,一定要存在对应的描述文件属性的结构体,类似与PCB.


www.dongchedi.com/article/7594897166766965272
www.dongchedi.com/article/7594897310665245246
www.dongchedi.com/article/7594897192310407705
www.dongchedi.com/article/7594897631617794585
www.dongchedi.com/article/7594896580080435737
www.dongchedi.com/article/7594895704896684568
www.dongchedi.com/article/7594897374330503705
www.dongchedi.com/article/7594895618720449048
www.dongchedi.com/article/7594896034183397912
www.dongchedi.com/article/7594896087656694334
www.dongchedi.com/article/7595300698343260734
www.dongchedi.com/article/7595300086620734014
www.dongchedi.com/article/7595300794661257753
www.dongchedi.com/article/7595300922285146649
www.dongchedi.com/article/7595300794661159449
www.dongchedi.com/article/7595301535278858814
www.dongchedi.com/article/7595300053246837310
www.dongchedi.com/article/7595298997771141656
www.dongchedi.com/article/7595298747215987224
www.dongchedi.com/article/7595298653444080190
www.dongchedi.com/article/7595299173835276862
www.dongchedi.com/article/7595293834620191257
www.dongchedi.com/article/7595294214674596377
www.dongchedi.com/article/7595294735703966270
www.dongchedi.com/article/7595294214674825753
www.dongchedi.com/article/7595269939515703870
www.dongchedi.com/article/7595270106293600793
www.dongchedi.com/article/7595268901785584153
www.dongchedi.com/article/7595268784974545433
www.dongchedi.com/article/7595270592459506238
www.dongchedi.com/article/7595268816629219865
www.dongchedi.com/article/7595267640395235902
www.dongchedi.com/article/7595267822872166937
www.dongchedi.com/article/7595266120056422936
www.dongchedi.com/article/7595265326464795161
www.dongchedi.com/article/7595264479055970878
www.dongchedi.com/article/7595263814942376472
www.dongchedi.com/article/7595263889965924926
www.dongchedi.com/article/7595264219466121753
www.dongchedi.com/article/7595261441830486590
www.dongchedi.com/article/7595257155528409624
www.dongchedi.com/article/7595257148431974937
www.dongchedi.com/article/7595255577883198014
www.dongchedi.com/article/7595257264999858713
www.dongchedi.com/article/7595255131160085054
www.dongchedi.com/article/7595254038942401086
www.dongchedi.com/article/7595272535034430014
www.dongchedi.com/article/7595273235844137496
www.dongchedi.com/article/7595271162356302398
www.dongchedi.com/article/7595269071357231641
www.dongchedi.com/article/7595269220477567512
www.dongchedi.com/article/7595268287076958782
www.dongchedi.com/article/7595269071357264409
www.dongchedi.com/article/7595268315833270809
www.dongchedi.com/article/7595265492903363096
www.dongchedi.com/article/7595265055567299096
www.dongchedi.com/article/7595265773019841049
www.dongchedi.com/article/7595265891500114494
www.dongchedi.com/article/7595264904798978585
www.dongchedi.com/article/7595263429863195161
www.dongchedi.com/article/7595261995696800280
www.dongchedi.com/article/7595258440394818073
www.dongchedi.com/article/7595256795065893401
www.dongchedi.com/article/7595256961541767704
www.dongchedi.com/article/7595257257731408446
www.dongchedi.com/article/7595253896583774745
www.dongchedi.com/article/7595252944199778841

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/22 23:23:49

从零实现74194四位移位寄存器功能验证实验

从零实现74194四位移位寄存器功能验证实验为什么我们今天还要“搭”一个74194&#xff1f;你可能已经习惯了在FPGA里用Verilog写一行shift_reg < {shift_reg[6:0], din};就搞定8位右移。但你知道这行代码背后&#xff0c;其实藏着几十年前工程师们用面包板和跳线一步步摸索出…

作者头像 李华
网站建设 2026/4/23 13:18:47

GHelper深度解析:如何用轻量工具彻底释放ROG设备潜能

GHelper深度解析&#xff1a;如何用轻量工具彻底释放ROG设备潜能 【免费下载链接】g-helper Lightweight Armoury Crate alternative for Asus laptops. Control tool for ROG Zephyrus G14, G15, G16, M16, Flow X13, Flow X16, TUF, Strix, Scar and other models 项目地址…

作者头像 李华
网站建设 2026/4/22 22:31:39

FanControl软件深度解析与风扇控制技术实践

FanControl软件深度解析与风扇控制技术实践 【免费下载链接】FanControl.Releases This is the release repository for Fan Control, a highly customizable fan controlling software for Windows. 项目地址: https://gitcode.com/GitHub_Trending/fa/FanControl.Releases …

作者头像 李华
网站建设 2026/4/23 11:35:03

如何快速部署通义千问2.5-7B-Instruct?免配置镜像入门必看教程

如何快速部署通义千问2.5-7B-Instruct&#xff1f;免配置镜像入门必看教程 1. 引言&#xff1a;为什么选择通义千问2.5-7B-Instruct&#xff1f; 在当前大模型快速迭代的背景下&#xff0c;通义千问2.5-7B-Instruct 凭借其“中等体量、全能型、可商用”的定位&#xff0c;成为…

作者头像 李华
网站建设 2026/4/19 18:14:15

小白必看!MinerU智能文档理解保姆级教程:从上传到分析

小白必看&#xff01;MinerU智能文档理解保姆级教程&#xff1a;从上传到分析 1. 学习目标与前置知识 本文是一篇面向初学者的完整入门指南&#xff0c;旨在帮助你快速掌握 MinerU 智能文档理解服务的使用方法。无论你是学生、研究人员还是办公人员&#xff0c;只要需要处理 …

作者头像 李华
网站建设 2026/4/23 13:04:59

OpenCode插件开发:扩展AI编程助手功能的完整教程

OpenCode插件开发&#xff1a;扩展AI编程助手功能的完整教程 1. 引言 1.1 学习目标 本文将带你从零开始掌握OpenCode插件开发的全流程。学完本教程后&#xff0c;你将能够&#xff1a; 理解OpenCode插件系统的核心架构创建并注册自定义功能插件实现代码质量分析类插件的完整…

作者头像 李华