fopen()
Requires header file: #include
Function prototype: FILE *fopen(const char *path,const char *mode)
Function parameters: path: the path and file name of the file to be opened
mode: file opening method, see below
Function return value: Success: FILE type pointer pointing to the file
Failure: NULL
The following are the allowed values and descriptions of the mode parameter:
r or rb opens the file in read-only mode. The file must exist
r+ or r+b opens the file in a readable and writable manner. The file must exist
w or wb opens the file in write-only mode. If the file does not exist, it is created; if the file exists, the original content of the file is erased and the file is operated from the beginning.
w+ or w+b opens the file in a readable and writable manner. If the file does not exist, it is created; if the file exists, the original content of the file is erased and the file is operated from the beginning.
a or ab opens a write-only file in append mode. If the file does not exist, it is created; if the file exists, the written data is appended to the end of the file, that is, the original content of the file will be retained.
a+ or a+b opens a readable and writable file in append mode. If the file does not exist, it is created; if the file exists, the written data is appended to the end of the file, that is, the original content of the file will be retained.
}
gets(), fgets()
Requires header file: #include
Function prototype: char *gets(char *s)
char *fgets(char *s,int size,FILE *stream)
Function:
Assume that the length of buff is MAX; then there are two ways to stop fgetc:
1. When reading /n, write the ascii of /n into buff and stop, and add a '\0' at the end;
2. When size-1 characters are read but no /n is read, the sequence ends and a '\0' is added at the end;
Function parameters: s: buffer address where input characters are stored
size: the length of the input string
stream: input file stream
Function return value:
Success:s
Failure or end of file: NULL
puts(), fputs()
Requires header file: #include
Function prototype: int puts(const char *s)
int fputs(const char *s,FILE *stream)
Function parameters: s: buffer address where output characters are stored
stream: output file stream
Function return value: Success: non-negative number
Failure: EOF
scanf(), fscanf(), sscanf()
Requires header file: #include
Function prototype: int scanf(const char *format,...);
int fscnaf(FILE *fp,const char *format,...);
int sscanf(char *buf,const char *format,...);
Function parameters: format: input format
fp: stream to be input
buf: buffer to be input
Function return value: Success: the number of data read
Failure: EOF
printf(), fprintf(), sprintf()
Requires header file: #include
Function prototype: int printf(const char *format,...);
int fprintf(FILE *fp,const char *format,...);
int sprintf(char *buf,const char *format,...);
Function parameters: format: output format
fp: stream to be output
buf: buffer to be output
Function return value: Success: Number of characters output
Failure: EOF
fread()
Requires header file: #include
Function prototype: size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
Function parameters: ptr: buffer for storing read data
size: The size of each data item read (in bytes)
nmemb: number of data read
stream: the stream to read
Function return value:
Success: The actual number of nmemb read
Failure: 0
fwrite()
Requires header file: #include
Function prototype: size_t fwrite(void *ptr,size_t size,size_t nmemb,FILE *stream);
Function parameters: ptr: buffer to store written data
size: The size of each data item written (in bytes)
nmemb: Number of data written
stream: the stream to write to
Function return value: Success: The actual number of nmemb written
Failure: 0
The feof()/ferror() functions can be used to determine whether the read operation is wrong or the file has been read to the end.
When opening a stream, the offset is 0 (the beginning of the file).
fseek()
Requires header file: #include
Function prototype: int fseek(FILE *stream, long offset, int whence);
Function parameters: stream: the stream to be positioned
offset: offset relative to the reference point whence
whence: reference point (values see below)
Function return value: Success: 0, change the read and write position
Failure: EOF, no change in read or write position
The value of the third parameter whence is as follows:
SEEK_SET: represents the starting position of the file, the number is 0
SEEK_CUR: represents the current read and write position of the file, the number is 1
SEE
K_END: represents the end position of the file, the number is 2
Function ftell()
Requires header file: #include
Function prototype: int ftell(FILE *stream);
Function parameters: stream: the stream to be positioned
Function return value: Success: Returns the current read and write position
Failure: EOF
Previous article:Embedded C code optimization
Next article:How to use C language variable parameter function
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- 【ST NUCLEO-H743ZI Review】 (4) - DCMI OV7620 Collection
- stm32f1 plays badaplle routine, modify the atomic routine, use vs1053 to decode audio, ucosII to do dual thread
- [New Year's Taste Competition] + Share your New Year's Eve dinner, wishing everyone a happy New Year! All the best!
- Based on AM335X development board ARM Cortex-A8——Acontis EtherCAT master station development case
- Practical sharing: Power management basics
- Device Identification
- High integration, high measurement speed, high precision, how does a flow cytometer achieve maximum performance?
- When multiple slaves successfully connect to the host, how can the host know which slave is sending data?
- Questions about the display screen supported by GUI
- Why can't the WiFi of every household in the densely packed urban communities be shared like 5G base stations?