Current location - Quotes Website - Personality signature - How to use fread function in C language
How to use fread function in C language

the syntax of fread function in c language is size_t? fread(? void? *restrict? buffer,? size_t? size,? size_t? count,? FILE? *restrict? stream? )。 Buffer is a pointer to the first object in the array to be read, size is the size of each object (in bytes), count is the number of objects to be read, and stream is the input stream. Fread function can be used to read data and return the number of objects successfully read.

Extended data:

fread function reads up to count objects from a given input stream into the array buffer (equivalent to calling fgetc for each object size times), treats the buffer as an unsignedchar array and saves the results in sequence. The number of bytes read forward by the file position indicator of the stream.

if an error occurs, the location of the file location indicator of the stream is uncertain. If the last element is not read completely, its value is uncertain and may be less than count. If size or count is zero, fread returns zero and does nothing else. Fread does not distinguish between file endings and errors, so callers must use feof and ferror to judge what happened.