Date: Sun, 9 Jun 2002 18:34:44 +0200 From: Erik Trulsson <ertr1013@student.uu.se> To: "Christopher J. Umina" <FJU@Fritzilldo.com> Cc: Giorgos Keramidas <keramida@ceid.upatras.gr>, FreeBSD Questions <questions@FreeBSD.ORG> Subject: Re: Load Averages with C Message-ID: <20020609163444.GA36956@falcon.midgard.homeip.net> In-Reply-To: <001901c20fe2$9988cc60$0301a8c0@uminafamily.com> References: <001201c20f54$46ba9e20$0301a8c0@uminafamily.com> <20020608222753.GA38586@hades.hell.gr> <001901c20fe2$9988cc60$0301a8c0@uminafamily.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Jun 09, 2002 at 11:22:21AM -0700, Christopher J. Umina wrote:
> Why when I use getloadavg(3) do I come out with wierd numbers?
>
> This is my code.
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(void) {
> int i;
> double loadavg[3];
> int getloadavg(double loadavg[], int nelem);
>
> for (i = 0; i < 3; ++i) {
> printf ("%d\n", loadavg[i]);
> }
> }
>
> and my output is always different, but it's:
>
> %./loadavg
> 1
> 4
> 663
>
> This time. What can I do to make these numbers correct?
>
> What am I doing wrong?
You should learn C a bit better.
In your program you don't actually call getloadvg(), you just declare
it inside your function. You also try to print doubles as integers.
Try this program instead:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
double avg[3];
int i;
getloadavg(avg,3);
for(i=0;i<3;i++)
{
printf("%f\n",avg[i]);
}
return 0;
}
--
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020609163444.GA36956>
