[comp.lang.c] comp.lang.c

tony@ajfcal.UUCP (Tony Field) (01/18/89)

I would like to know the *correct* method of posting sources to
comp.sources.unix.

Can anyone give me the directions???

           thanks,       tony..
-- 
+------------------------------------
|  Tony Field                       ..alberta!calgary!xenlink!ajfcal!tony
|  Calgary, Alberta, Canada

bchurch@oucsace.cs.OHIOU.EDU (Bob Church) (08/28/89)

I've just started reading this newsgroup so forgive me if this is
an old question. I am trying to get the return value of fread into
a variable. The following line
while (rtns = (fread(buf,5,10,ioptr)) == 10)
rtns being an integer works as long as their are
50 byte chunks of data left to be read. The problem is that the
value that I then in rtns after each pass is either 1 if
successful or 0 on the last pass when the data has all been read.
How can I get the actual number of items read into a variable that
I can then use in the fwrite command? 
Thanks,

Bob Church
att!oucsace!bchurch
or CS656@OUACCVMB on the Bitnet

gwyn@smoke.BRL.MIL (Doug Gwyn) (08/28/89)

In article <744@oucsace.cs.OHIOU.EDU> bchurch@oucsace.cs.OHIOU.EDU (Bob Church) writes:
>while (rtns = (fread(buf,5,10,ioptr)) == 10)

while ( (rtns = fread( buf, 5, 10, ioptr )) == 10 )

ark@alice.UUCP (Andrew Koenig) (08/28/89)

In article <744@oucsace.cs.OHIOU.EDU>, bchurch@oucsace.cs.OHIOU.EDU (Bob Church) writes:

> The following line
> while (rtns = (fread(buf,5,10,ioptr)) == 10)
> rtns being an integer works as long as their are
> 50 byte chunks of data left to be read.

Your problem is that == binds more tightly than =, so that is
equivalent to

	while (rtns = ((fread(buf,5,10,ioptr)) == 10))

Instead you should say

	while ((rtns = fread(buf,5,10,ioptr)) == 10)
-- 
				--Andrew Koenig
				  ark@europa.att.com

cpcahil@virtech.UUCP (Conor P. Cahill) (08/28/89)

In article <744@oucsace.cs.OHIOU.EDU>, bchurch@oucsace.cs.OHIOU.EDU (Bob Church) writes:
> while (rtns = (fread(buf,5,10,ioptr)) == 10)

should be:

while( (rtns = fread(buf,5,10,iopr)) == 10)


(you had the parens in the wrong place which caused the result of the 
comparison to be assigned to rtns.



-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+

davek@hp-lsd.COS.HP.COM (Dave Kumpf) (08/29/89)

How about:

while ((rtns = fread(buf,5,10,ioptr)) == 10)

(i.e. fread, store return value in rtns, then compare it to 10)


Your version compares the result of the fread to 10 and stores the 
result in rtns (either 1 or 0). (I think.)

Dave Kumpf
hplabs!hp-lsd!davek