C Programming/stdio.h/fread

From Wikibooks, open books for an open world
Jump to navigation Jump to search

fread is a function that reads buffered binary input from a file.[1] It is included from the stdio.h header file in the standard C library.

size_t fread (void * restrict ptr, size_t size, size_t nmemb, FILE * restrict stream)

The fread function copies nmemb items of data of size size from the named input stream into an array pointed to by ptr. An item of data is a sequence of bytes (not necessarily terminated by a null byte) of length size. fread stops appending bytes when nmemb items have been read, end of file has been reached, or an error has occurred. Upon returning, fread sets the file pointer in the stream pointing to the byte past the last byte that has been read. The contents of stream remain unchanged. The fread function returns the number of items actually read. If nmemb is zero, no action is taken and the function will return 0.

References[edit | edit source]

External links[edit | edit source]