当前位置:网站首页>Explain the operation of C language file in detail
Explain the operation of C language file in detail
2022-07-19 14:30:00 【Finally - null】
Make a little progress every day , Persistence makes a big difference !!!

Catalog
2. Opening and closing of files :
2. Closing and opening of files :
3. Sequential reading and writing of files :
3. Random reading and writing of documents :
Preface :
When we want to save data , You can use files to store data directly on the hard disk of your computer , In this way, the data can be permanently saved
1. What is a document :
The files on disk are files , But in programming , We generally talk about two kinds of documents : Program files and data files
1. Program files :
Include source files ( The suffix is .c), Target file (windows Environment suffix is .obj), Executable program (windows Environment suffix is .exe).
2. Data files :
The content of the file is not necessarily a program , It's the data that the program reads and writes when it runs , For example, the file from which the program needs to read data , Or output content file .
3. file name :
File path + File name trunk + file extension
2. Opening and closing of files :
1. The file pointer :
Each used file opens a corresponding file information area in memory , It is used to store information about files , These file information is stored in a structure variable , named FILE
Define a file pointer variable :
FILE*pf
2. Closing and opening of files :
Opening of files :fopen
FILE*fopen(constchar*filename,constchar*mode);
Closing of files :fclose
intfclose(FILE*stream);
Open mode :
3. Sequential reading and writing of files :
1. Write a character :
intfputc(intc,FILE*stream);
2. Read a character :
intfgetc(FILE*stream);
3. Write a line of data :
intfputs(constchar*string,FILE*stream);
4. Read a row of data :
char*fgets(char*string,intn,FILE*stream);
5. Format input data :
Format data : Contains various data types
intfprintf(FILE*stream,constchar*format [, argument ]...);
6. Format output data :
intfscanf(FILE*stream,constchar*format [, argument ]... );
7. Output data in binary form :
size_tfwrite(constvoid*buffer,size_tsize,size_tcount,FILE*stream);
take count Size is size The data of is output to the file stream in binary form
Because the file is written in binary form , Therefore, you cannot read the contents of the document with the naked eye
8. Read data in binary form :
size_tfread(void*buffer,size_tsize,size_tcount,FILE*stream);
take count Size is size The data of is read out in binary form from the file
4. Compare several sets of functions :
scanf: Is a formatted input statement for a standardized input stream
printf: Is a formatted output statement for a standardized output stream
fscanf: It is a formatted input statement for all input streams
fprintf: Is a formatted output statement for all output streams
sscanf:
int sscanf( const char *buffer, const char *format [, argument ] ... );
Convert a string to a formatted output statement
sprintf:
int sprintf( char *buffer, const char *format [, argument] ... );
Convert the formatted input statement into the corresponding string :
3. Random reading and writing of documents :
1.fseek:
Locate the file pointer according to its position and offset :
intfseek(FILE*stream,longoffset,intorigin );
2.ftell
Returns the offset of the file pointer from the starting position :
longftell(FILE*stream);
3.rewind
Return the file pointer to the starting position :
voidrewind(FILE*stream);
4. Text files and binaries :
text file : With ASCII The data stored in a file in the form of is called a text file
Binary : Data is stored in binary form in memory , If it is stored directly in a file without conversion, it is a binary file
5. Determination of the end of file reading :
1.feof
intfeof(FILE*stream);
Out-of-service feof The return value of is directly used to determine whether the file ends , Instead, it applies when the file reading ends , The judgment is that the read failed and ended , Or end of file
1. End of text file reading :
fgetc Judge whether it is EOF.
fgets Determine whether the return value is NULL.
2. Binary file reading finished :
fread Judge whether the return value is less than the actual number to be read .
1. Examples of text files :
2. Examples of binary files :
6. File buffer :
Data output from memory to disk is first sent to a buffer in memory , After the buffer is filled, it is sent to the disk together . If you read data from disk to computer , Then read the data from the disk file and input it into the memory buffer ( Fill the buffer ), And then send the data from the buffer to the program data area one by one ( Program variables, etc ). The size of the buffer depends on C The compiler system decides .
summary : So that's about C Detailed explanation of language file operation knowledge points , I hope I can help each other in the learning of programming , Promote each other , Welcome to like , Leave a comment !!!
边栏推荐
- 05--- antireflective film
- Excellent jar package startup shell script collection
- Unveil the mystery of service grid istio service mesh
- Take a look at try{}catch{}
- Overview report of Chinese AI medical imaging industry in 2022
- Okaleido或杀出NFT重围,你看好它吗?
- Huawei wireless device configuration dynamic load balancing
- Unity subtitle scrolling
- Redis source code and design analysis -- 4 Jump table
- Redis source code and design analysis -- 2 Linked list
猜你喜欢

Robotics at Google:Laura Graesser | i-Sim2Real:在紧密的人机交互循环中强化学习机器人策略

96. 不同的二叉搜索树

Use tongweb's hot deployment function with caution

Colliding Mice碰撞老鼠工程分析

Take a look at try{}catch{}

Redis 与 Mysql 的数据一致性
![Luo Gu: p3092 [usaco13nov]no change G](/img/b9/8cacd3d4ae1cf014654e0204cb3a62.png)
Luo Gu: p3092 [usaco13nov]no change G

CMAKE学习笔记

2022年中国AI医学影像行业概览报告

The manual is not complete. How to manually dig out the monitoring information of tongweb?
随机推荐
Notes with a face value of 10exp (303)
Brief introduction of Bezier curve
ospf-LSA
4某公司在6个城市c1,c2,c3…c6中有分公司,已知城市ci到cj(I,j=1,2,3,…6)的联通情况下及费用的大小列于以下带权邻接矩阵中C中
Prefix Equality 【DP | 哈希】
Tree and bipartite graph [thinking]
C # read and write text and generate QR code
[dynamic programming] - longest ascending subsequence model
00 后博士获聘南大特任副研究员,曾 4 岁上小学,14 岁考入南大!
Wechat applet -- wxss template style
慎用TongWeb的热部署功能
A Classical Review of nonconvex optimization problems from Symmetry to Geometry, Rochester University, etc.
C - pointer
ping 命令还能这么玩?
CF 807 E. mark and Professor Koro (weight segment tree)
陶博士月线反转6.0
微信小程序---wxss模板样式
Robotics at google:laura Graesser | i-sim2real: strengthen the learning robot strategy in the close human-computer interaction cycle
华为无线设备配置动态负载均衡
96. Different binary search trees






















