C (36/207)

From:Colin Wenzel
Date:04 Dec 99 at 15:21:24
Subject:Re: cps counter

From: Colin Wenzel <colstv@hotkey.net.au>

> From: YvesGrabowsky@t-online.de (Yves Grabowsky)
> Hi,
> I'm trying to calculate the cps of a transfer with the following
> code:
>
> --------CUT HERE-----------
> long n, temp, cps;
> time_t start, current;
>
> start = time(&start);
// firstly, (&start) is filled by time(), so equating the return
// value is pointless... a NULL may be passed to: time(NULL)
// if you dont want it to fill in the result...
// or you can: (void)time(&start);
// whatever you prefer...
>
> do
> {
> n = Sock_Recv(dtc, buf, LEN_RECVBUF);
// I have no info on this function....

> temp += n;
// temp is not initialized.....

> if (n>0)
> Write(outfile, buf, n);
// is the filehandle valid..... ??
// is buf[] initialized ok & is it big enough..... ?
>
> current = time(&current); // cps calculation
// same thing here as: time(&start).......................

> current -= start;
> cps = temp / current;
// divide by zero error here if current == 0 .......

// use: cps = 0L;
// if(current)
// cps = temp / current;

> } while(n); // receive loop
>
> (temp holds the bytes received)
> -----------CUT HERE-------------
>
> Everytime I execute this code it crashes, without the cps
> calculation it runs perfectly. Whats wrong with this?
>
-------------------------------------
Colin Wenzel. Australia.

EMAIL: mailto:colstv@hotkey.net.au
URL: http://www.hotkey.net.au/~colstv/
ICQ: 17608330
MADE WITH 'AMIGA' 4000T With O.S 3.1
---------------------------------------