.\" Copyright (c) 1990, 1991 The Regents of the University of California. .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" Chris Torek and the American National Standards Committee X3, .\" on Information Processing Systems. .\" .\" %sccs.include.redist.man% .\" .\" @(#)fread.3 6.6 (Berkeley) 06/29/91 .\" .Dd .Dt FREAD 3 .Os .Sh NAME .Nm fread , .Nm fwrite .Nd binary stream input/output .Sh SYNOPSIS .Fd #include .Ft int .Fn fread "void *ptr" "size_t size" "size_t nmemb" "FILE *stream" .Ft int .Fn fwrite "void *ptr" "size_t size" "size_t nmemb" "FILE *stream" .Sh DESCRIPTION The function .Fn fread reads .Fa nmemb elements of data, each .Xr size bytes long, from the stream pointed to by .Fa stream , storing them at the location given by .Fa ptr . .Pp The function .Fn fwrite writes .Fa nmemb elements of data, each .Fa size bytes long, to the stream pointed to by .Fa stream , obtaining them from the location given by .Fa ptr . .Sh RETURN VALUES The functions .Fn fread and .Fn fwrite advance the file position indicator for the stream by the number of characters successfully read or written and return that number. If an error occurs, or the end-of-file is reached, the return value is a short character count (or zero). .Pp The function .Fn fread does not distinguish between end-of-file and error, and callers must use .Xr feof 3 and .Xr ferror 3 to determine which occurred. .Sh SEE ALSO .Xr read 2 , .Xr write 2 .Sh STANDARDS The functions .Fn fread and .Fn fwrite conform to .St -ansiC .