Relevant content of the document (2)

Compare the following three sets of functions

scanf/fscanf/sscanf

printf/fprintf/sprintf

scanf function: is a formatted input statement for the standard input stream;

printf function: is a formatted output statement for the standard output stream;

fscanf function: is a formatted input statement for all input streams;

fprintf function: is a optimized output statement for all output streams;

sscanf function: Convert a formatted data from a string;

The sprintf function: writes formatted data into a string. Its essence is to convert the formatted data into a string.

We have already studied the first two sets of functions before, let's learn the following set of functions:

sprintf function: (The static modification here is because the stack in the program is full, so this character is created in the static area).

To write formatted data into a string, it has several parameters: the first parameter is: the starting address of the string to be written, and the other parameters are the same as the parameters of scanf.

3ea4e9ca18b14aa897e4d009d3c0db96.png

 sscanf function: The parameter definitions of the sprintf function are similar. We need to fill in the pointer of the first parameter correctly.

b7ed1527996247858930533c74937945.png

The purpose of these two functions:

Get some information in the front end, such as name, age, phone number, etc. There will be a string passed to the backend, the backend receives the formatting that converts the string into a structure, and then converts the information into a string and passes it to the frontend for legal serialization.

Random reading and writing of files:

There are three functions (fseek, ftell, rewind);

The first function is the fseek function. The fseek function has three parameters: the first parameter corresponds to the stream, the second parameter is the offset of the current file address, and the third parameter is a macro with three values ​​as shown in the figure. Shown:

0609a4ae2bf443b7ae7a2a09c8a735a9.png

SEEK_SET refers to the starting position of the file, SEEK_CUR is the position of the current file pointer, and SEEK_END is the end of the file.

The incoming stream of the ftell function can tell the offset of the pointer's position relative to the starting position, and the rewind function returns the file pointer to the starting position of the file. 

 

 

Guess you like

Origin blog.csdn.net/2301_77868664/article/details/130945833