From owner-freebsd-questions Sun Jun 9 9:34:57 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mailb.telia.com (mailb.telia.com [194.22.194.6]) by hub.freebsd.org (Postfix) with ESMTP id 9721637B400 for ; Sun, 9 Jun 2002 09:34:50 -0700 (PDT) Received: from d1o913.telia.com (d1o913.telia.com [195.252.44.241]) by mailb.telia.com (8.11.6/8.11.6) with ESMTP id g59GYl121815 for ; Sun, 9 Jun 2002 18:34:48 +0200 (CEST) Received: from falcon.midgard.homeip.net (h53n2fls20o913.telia.com [212.181.163.53]) by d1o913.telia.com (8.8.8/8.8.8) with SMTP id SAA23359 for ; Sun, 9 Jun 2002 18:34:46 +0200 (CEST) Received: (qmail 37058 invoked by uid 1001); 9 Jun 2002 16:34:44 -0000 Date: Sun, 9 Jun 2002 18:34:44 +0200 From: Erik Trulsson To: "Christopher J. Umina" Cc: Giorgos Keramidas , FreeBSD Questions Subject: Re: Load Averages with C Message-ID: <20020609163444.GA36956@falcon.midgard.homeip.net> Mail-Followup-To: "Christopher J. Umina" , Giorgos Keramidas , FreeBSD Questions References: <001201c20f54$46ba9e20$0301a8c0@uminafamily.com> <20020608222753.GA38586@hades.hell.gr> <001901c20fe2$9988cc60$0301a8c0@uminafamily.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <001901c20fe2$9988cc60$0301a8c0@uminafamily.com> User-Agent: Mutt/1.3.99i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 > #include > > 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 #include int main(void) { double avg[3]; int i; getloadavg(avg,3); for(i=0;i<3;i++) { printf("%f\n",avg[i]); } return 0; } -- Erik Trulsson ertr1013@student.uu.se To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message