【C language exercises】File operation

1. What is the way to open a file in C language in binary mode? ()

A.FILE *f = fwrite( “test.bin”, “b” );
B.FILE *f = fopenb( “test.bin”, “w” );
C.FILE *f = fopen( “test.bin”, “wb” );
D.FILE *f = fwriteb( “test.bin” );

First of all, because the file needs to be opened, AD is wrong, because there is no "fopenb" function, so select C directly. The b in the binary description should be placed after the permission, that is, "wb" is legal.

2. What is incorrect about the fopen function: ()

A.fopen uses "r" to open the file. If the file does not exist, it fails to
open the file. B.fopen uses "w" to open the file. If the file does not exist, the file is created and the file is opened successfully
. The return value does not need to determine
that the file opened by D.fopen needs to be closed by fclose

The return value of fopen in the C option can check whether the file is opened successfully, especially when the open mode is "r". ABD is the basic concept and principle of file operation.

3. What is wrong in the following statements about the file name and path: ()

A. There are some prohibited characters in the
file name B. The file name must contain the suffix
C. The file suffix determines the default opening method of a file
D. The file path refers to the experience from the drive letter to the file The collection of symbol names in the path

In option B, the file name does not need to include the suffix name. In the case of A, these characters cannot be included in the file: /*?"<>|:, C expresses the function of the suffix name, and D is the basic concept of the path. So choose B.

4. What is incorrect about the file read and write function in C language is: ()

A.fgetc is a character input function suitable for all input streams
B.getchar is also a character input function suitable for all streams
C.fputs is a text line output function suitable for all output streams
D.fread is a binary input suitable for file input streams function

In the B option, getchar is only for the standard input stream stdin. Even if stdin is redirected, getchar only targets stdin. The input and output functions of the f series are applied to all streams, so AC is fine, and D is fine. What fread does is binary.

Guess you like

Origin blog.csdn.net/weixin_43962381/article/details/109754691