Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Using fread function Date: Sun, 29 Jan 2017 13:14:46 -0800 Organization: None to speak of Lines: 26 Message-ID: References: <02c75a0c-84d7-4669-8bde-472730c7f8d3@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="0fd733d9f8cc5cb46740a4e887498fc9"; logging-data="28711"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3pDkfCqLHlwsy1LWj+ten" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:0bzULTTeDY0e8iFBaTPheDMW6BM= sha1:YLAb2+lEOoOXG2qhf9vADdY4Bec= Xref: csiph.com comp.lang.c:102729 janus writes: > I just noticed that swapping the positions of the inner parameters > does not have any material effect on result. That led me to think that > "fread" function just multiple the two parameters. > > size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); > > size_t fread(void *ptr, size_t nmemb, size_t size, FILE *stream); > > Is my position correct? I wrote about this here: http://stackoverflow.com/a/8589688/827263 Quick summary: fread() returns the number of elements it was able to read, and the ordering of the 2nd and 3rd arguments lets you define what an element is. Read a single data element if a partial read is no better than not reading anything at all. Read in smaller chunks if partial reads are useful. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"