news 2026/6/10 21:59:59

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/6/10 11:41:06

OpCore Simplify快速上手:构建完美黑苹果EFI的完整指南

OpCore Simplify快速上手&#xff1a;构建完美黑苹果EFI的完整指南 【免费下载链接】OpCore-Simplify A tool designed to simplify the creation of OpenCore EFI 项目地址: https://gitcode.com/GitHub_Trending/op/OpCore-Simplify OpCore Simplify是一款专为黑苹果用…

作者头像 李华
网站建设 2026/6/10 11:45:36

从零搭建高精度中文ASR|FunASR语音识别镜像使用全指南

从零搭建高精度中文ASR&#xff5c;FunASR语音识别镜像使用全指南 1. 学习目标与前置知识 1.1 学习目标 本文旨在帮助开发者和AI爱好者从零开始&#xff0c;快速部署并使用基于 FunASR 的高精度中文语音识别系统。通过本指南&#xff0c;您将掌握&#xff1a; 如何启动并配…

作者头像 李华
网站建设 2026/6/10 0:25:58

IQuest-Coder-V1如何高效推理?KV缓存优化部署实战

IQuest-Coder-V1如何高效推理&#xff1f;KV缓存优化部署实战 1. 引言&#xff1a;面向软件工程的下一代代码大模型 1.1 模型背景与核心定位 IQuest-Coder-V1-40B-Instruct 是 IQuest-Coder-V1 系列中专为通用编码辅助和指令遵循优化的指令模型变体&#xff0c;代表了面向软…

作者头像 李华
网站建设 2026/6/10 11:40:41

FanControl终极指南:Windows系统散热控制完整教程

FanControl终极指南&#xff1a;Windows系统散热控制完整教程 【免费下载链接】FanControl.Releases This is the release repository for Fan Control, a highly customizable fan controlling software for Windows. 项目地址: https://gitcode.com/GitHub_Trending/fa/Fan…

作者头像 李华
网站建设 2026/6/10 11:41:17

退休教授玩转Open Interpreter:70岁也能用的云端AI编程方案

退休教授玩转Open Interpreter&#xff1a;70岁也能用的云端AI编程方案 你是不是也以为“编程”是年轻人的专利&#xff1f;尤其是现在动不动就要装环境、配CUDA、调依赖&#xff0c;光看命令行就让人头大。但今天我要告诉你&#xff1a;70岁也能轻松上手AI编程&#xff01;而…

作者头像 李华
网站建设 2026/6/10 14:04:35

Bodymovin扩展面板3步安装指南:轻松实现AE动画导出

Bodymovin扩展面板3步安装指南&#xff1a;轻松实现AE动画导出 【免费下载链接】bodymovin-extension Bodymovin UI extension panel 项目地址: https://gitcode.com/gh_mirrors/bod/bodymovin-extension Bodymovin扩展面板是一款专为After Effects用户设计的动画导出工…

作者头像 李华