当前位置:网站首页>Basic knowledge of documents
Basic knowledge of documents
2022-07-25 18:10:00 【Swordsman】
Knowledge about documents
Classification of documents
- Program files : image
.cSource file for suffix ,.objTarget file for suffix ,.exeExecutable program with suffix . - Data files : Data when the program reads and writes .
Or according to another classification
The documents are divided into :1. text file .2. Binary .
Data is stored in binary form in memory , Output directly to external memory without conversion , Binary files ; If conversion is added , With ASCII Standard storage is text files .
Data files
file name : The unique identification of a file .
Include : File path , File name trunk , file extension
Opening and closing of files
- The file pointer
The file pointer is actually a structure variable name FILE, The members inside are used to store the relevant information of the file . These information together constitute the file information area of each different file .
Every time you open a file , The system will create different FILE, adopt FILE* Create a variable pf, there pf It's a file pointer , It can point to the corresponding file .
- Opening and closing of documents
Before reading and writing files , The file should be opened ; When the relevant operation is over , The file should be closed .
The standard specifies the use of fopen To open the file , use fclose To close the file .
fopen
FILE* fopen(const char* filename, const char* mode);
When the file is successfully opened , What is returned is a pointer to the structure of a specific file information area ; Open failure returns a null pointer , therefore , When using files , We have to judge .
How to open some important files
| How to open the file | Specific meaning | file does not exist |
|---|---|---|
| “r” | To input data, open the file | Report errors |
| “w” | To output data, open a file | Create a new file |
| “rb” | To enter data , Open a binary file | Report errors |
| “wb” | To output data , Open a binary file | Create a new file |
fclose
int fclose(FILE* stream);
give an example
#include <stdio.h>
#include <string.h>
#include <errno.h>
int main()
{
FILE* pf = fopen("test.txt", "w");
if (pf == NULL)
{
printf("%s\n", strerror(errno));
return;
}
// Document related operations
//...
fclose(pf);
return 0;
}
Sequential reading and writing of files
| function | Function name | Using range |
|---|---|---|
| Character input | fgetc | All input streams |
| Character output | fputc | All input streams |
| Text input | fgets | All input streams |
| Text output | fputs | All input streams |
| Format input | fscanf | All input streams |
| Format output | fprintf | All input streams |
| Binary input | fread | file |
| Binary output | fwrite | file |
Random reading and writing of documents
fseek
int fseek(FILE* stream, long offset, int origin);
This function is 3 Parameters , The first is a file pointer , The second is the offset , The third is the starting position .
If the starting position is the first element, it is 0, The last element is -1.
Through this 3 Parameters can be located to the relevant location of the file , Read and write .
ftell
long ftell(FILE* stream);
If the function returns normally , Returns the offset of the file pointer from the starting position .
rewind
void rewind(FILE* stream);
Let the file pointer point to the starting position of the file .
Judgment of the end of file reading
feof
int feof(FILE* stream);
This function is used to end the file , Judge whether the reading fails or the end of the file is encountered .
- Judge whether the reading of the text file is over :
fgetc Judge whether it is EOF
fgets Judge whether it is NULL
- Judge whether the reading of binary file is over
Judge whether the return value is less than the actual number to be read ,fread Judge whether the return value is less than the actual number to be read .
边栏推荐
- testng执行顺序的3中控制方法
- MySQL page lock
- MySQL数据库常用命令
- Memory and packet buffer management of LwIP
- Resttemplate realizes the unified encapsulation (printable log) of post, put, delete, get, set request and file upload (batch files and parameters) through generics
- Basic operation of bidirectional linked list
- Tkinter GUI address book management system
- How to read a Book
- Mock service Moco series (II) - JSON format, file file, header, cookie, solving Chinese garbled code
- 专访即构科技李凯:音视频的有趣、行业前沿一直吸引着我
猜你喜欢

BiSeNet v1

Lwip之内存与包缓冲管理

绘制pdf表格 (一) 通过itext实现在pdf中绘制excel表格样式并且实现下载(支持中文字体)

nodejs 简单例子程序之express

「数字安全」警惕 NFT的七大骗局

How to choose digital twin visualization platform

3DCAT v2.1.3新版本发布,这三大功能更新你不容错过!

Good news! Ruiyun technology was awarded the member unit of 5g integrated application special committee of "sailing on the sea"

SLA 、SLO & SLI

SLA 、SLO & SLI
随机推荐
SDLC software development life cycle and model
专访即构科技李凯:音视频的有趣、行业前沿一直吸引着我
二叉树的相关操作
STM8S003F3 内部flash调试
Tme2022 campus recruitment background development / operation development / business operation and maintenance / application development written examination (I) a little self analysis of programming q
CVE-2022-33891 Apache spark shell 命令注入漏洞复现
Error when starting MySQL on Linux
TME2022校园招聘后台开发/运营开发/业务运维/应用开发笔试(I)编程题的一点自我分析
testng执行顺序的3中控制方法
喜讯!瑞云科技被授予“海上扬帆”5G融合应用专委会成员单位
Which real-time gold trading platform is reliable and safe?
Update 3dcat real time cloud rendering V2.1.2 release
The use of invocationcount, threadpoolsize, timeout of concurrent tests in TestNG
绘制pdf表格 (一) 通过itext实现在pdf中绘制excel表格样式并且实现下载(支持中文字体)
imx6 RTL8189FTV移植
Introduction to cloud XR and development opportunities of cloud XR in 5g Era
"Deprecated gradle features were used in this build, making it incompatible with gradle 6.0" problem solving
mysql的小数number类型select之后丢失了前面的0
How many points did NPDP pass? How to pass with high scores?
Three control methods of TestNG execution sequence