MindMap Gallery Standard IO
This is a mind map about standard IO. The main contents include: standard IO stream, standard file IO related functions, standard file IO cache area, and file IO.
Edited at 2024-11-28 17:59:01CBT cognitive behavioral therapy, cognitive therapy, psychological counseling, CBT basic concept: ideas determine emotions, experience determines ideas, experience requires comparison to be meaningful, and there are individual differences in experience.
Psychological perception, perception is generated on the basis of sensation. It is the response of the human brain to the objective things and overall attributes that directly act on the sensory organs. The introduction is detailed, students in need can save it.
心理學知覺,知覺在感覺的基礎上產生它是人腦對直接作用於感覺器官的客觀事物,整體屬性的反應。介紹詳細,有需要的同學,可以收藏喲。
CBT cognitive behavioral therapy, cognitive therapy, psychological counseling, CBT basic concept: ideas determine emotions, experience determines ideas, experience requires comparison to be meaningful, and there are individual differences in experience.
Psychological perception, perception is generated on the basis of sensation. It is the response of the human brain to the objective things and overall attributes that directly act on the sensory organs. The introduction is detailed, students in need can save it.
心理學知覺,知覺在感覺的基礎上產生它是人腦對直接作用於感覺器官的客觀事物,整體屬性的反應。介紹詳細,有需要的同學,可以收藏喲。
day1
Standard IO stream
There are several standard IO streams
Stream is the operation object of the standard IO core
After a program starts executing, three streams will be automatically opened.
The standard input stream stdin defaults to input from the keyboard
Standard output stream strout default terminal output
The standard error output stream strerr outputs to the terminal by default
The difference between standard output stream and standard error output stream
The standard output stream exists in the buffer. The standard error output stream does not exist in the buffer.
Standard stream interview questions
It is known that the standard output stream is cached. Please list the possible situations in which the contents of the cache area appear on the terminal. 1) Meet ' ' 2) The buffer area is full 3) Stream closed 4) fflush forces refresh
FileIO
What is file IO
Operations related to input and output of files //Open the file, read the file, write the file, close the file //I input O output
Classification of file IO
1. Standard IO//The file-related operations in the standard C library belong to library functions 2. LinuxIO//The file-related operations provided by the Linux system are system calls.
1. System call (1) The interface for user space processes to access the kernel (2) Free users from underlying hardware programming (3) Greatly improves the security of the system (4) Make user programs portable 2. Library functions (1) A collection of APIs encapsulated by library functions to implement a certain function (2) Provide a unified programming interface to make it easier to transplant applications
Standard file IO exists in the cache area
Full cache
//Standard IO exists in the buffer //Not adding ' ' means full cache. When the buffer area is full, it will be processed by the operating system for unified printing. //The default size of the cache area is 1024 bytes
Line cache (only available for terminals)
//With the addition of , the full cache becomes a line cache. The output content will not stay in the cache area. When ' ' is encountered, it will be handed over to the operating system for processing and then printed on the terminal. //Note: The concept of line caching will only exist when the output object is a terminal.
Standard file IO related functions
1. fopen function
Function: open file
Parameter description
return value FILE* pointer, file stream pointer, FILE is a structure. Every time a file is opened, the kernel will open up a space to save the relevant information obtained by opening the file. success: Return FILE* (non-empty)//Stream stream is the core object of standard IO fail: Return NULL
2. fgetc function
Function: Read one character at a time (read literally)
Parameter description
return value success: The ascii value corresponding to the actually read character Failure: //When the tail of the file is read, the return value is EOF, which is -1 The return value is -1 Return EOF(-1) #define EOF -1
3. fputc function
Function: Write a character to the file
Parameter description
4. fclose function
Function: Close the file, refresh the cache area, and clear the contents of the cache area.
Parameter description
return value success: Return 0 fail: Return -1
Return value: success: Returns the characters written fail: Return -1
Exercise 1
5. perror function
Parameter description
return value none
6. strerror function
Function: Function to print error message There is a global variable in the Linux system. errno is used to save the error message number. The printing of error output information is based on the error number.
Parameter description
Return value: char * The first address of the error cause string "No such file or directory"
7. fgets function
Function: Read one line at a time ( The newline character is used as the terminator of reading)
Parameter description
Return value: success: char * //The first address of the line of string read out fail: Returns NULL, returns NULL when reading to the end of the file
8. fputs function
Function: Write a string each time
Parameter description
Return value: success: >= 0 //non-negative number fail: Return EOF
Exercise 2
9. fread function
Function: Read content at specified size Read one segment at a time (note that one segment is measured in blocks)
Parameter description
Return value: success: Number of blocks actually read The actual number of records read Number of objects actually read It cannot be said that it represents the actual number of bytes read. fail: less than or equal to 0
10. fwrite function
Function: write in blocks
Parameter description
Return value: success: Number of blocks actually written fail: less than 0
11. sprintf, fprintf function
sprintf
Function: Write the formatted string into a character array
parameter
fprintf
Function: Write the formatted string into the file opened corresponding to stream
parameter
printf sprintf fprintf difference
1. printf outputs a formatted string to the terminal sprintf outputs a formatted string to a character array fprintf outputs a formatted string to a file device 2. sprintf and fprintf cannot be redirected, but printf can be redirected.
12. memset function
Function: memory setting function, memset is an initialization function, The function is to set everything in a certain block of memory to the specified value.
Parameter description
Return value: The starting address of the set memory space
13. fseek function
Function: The file pointer is a member variable in the FILE structure. Move the position of the file pointer.
Parameter description
Return value: Success: 0 Failure: EOF -1
14. ftell function
Function: Get the position of the file pointer The file pointer's position index starts from 0
Parameter description
return value Success: Returns the position of the current file pointer Failure: EOF