From owner-freebsd-hackers Thu May 16 11:56:14 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id LAA24369 for hackers-outgoing; Thu, 16 May 1996 11:56:14 -0700 (PDT) Received: from freebsd.ki.net (root@freebsd.ki.net [205.150.102.51]) by freefall.freebsd.org (8.7.3/8.7.3) with ESMTP id LAA24363 for ; Thu, 16 May 1996 11:56:10 -0700 (PDT) Received: from localhost (scrappy@localhost) by freebsd.ki.net (8.7.5/8.7.3) with SMTP id OAA07854 for ; Thu, 16 May 1996 14:56:37 -0400 (EDT) X-Authentication-Warning: freebsd.ki.net: scrappy owned process doing -bs Date: Thu, 16 May 1996 14:56:36 -0400 (EDT) From: "Marc G. Fournier" To: hackers@freebsd.org Subject: C Programming Question Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Hi... I'm trying to do something that I feel should be relatively brain dead to do, but can't get it to work...change an ascii string to a double. I've tried using atof() and strtod(), and both return the same answer...0. The code is simple, and right now, just pulls the first line from a file to manipulate it: ---[ short code segment ]---- #include #include #define DATAFILE "/home/staff/scrappy/snmp/values" main(int argv, char **argc) { FILE *in; char inbuf[80], *junk, str[20]; double value; in=fopen(DATAFILE, "r"); fgets(inbuf, sizeof(inbuf), in); printf("inbuf: %s\n", inbuf); junk = strtok(inbuf, " "); junk = strtok(NULL, " "); strcpy(str, junk); printf("%s\n", str); value = strtod(str, NULL); printf("[%f]\n", value); fclose(in); } ----[ end of code ]---- the output, when running this, looks like: ki> ./double inbuf: 832220635 1980972567 2198208632 1980972567 [0.000000] Using atof() instead of strtod() gives the same result, so the only thing I can think of is I'm missing something *really* simple here. If I change it to use atoi(), the value comes up correctly, but the second value in the inbuf comes out as: 2198208632 [2147483647] Trying to set 'value' to be an unsigned int has the same result, as well as unsigned long/atol()...nothing wants to exceed the 2147483647 barrier. So...is it something I'm missing? According to the Unix C reference I have, a 4byte int, unsigned, should give me 0->4294967295, but I'm only getting half of that. Marc G. Fournier scrappy@ki.net Systems Administrator @ ki.net scrappy@freebsd.org