From owner-freebsd-current Fri May 24 10:53:39 2002 Delivered-To: freebsd-current@freebsd.org Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net [194.217.242.93]) by hub.freebsd.org (Postfix) with ESMTP id 16B0C37B408; Fri, 24 May 2002 10:53:33 -0700 (PDT) Received: from teabag.demon.co.uk ([193.237.4.110] helo=teabag.cbhnet) by anchor-post-35.mail.demon.net with esmtp (Exim 3.35 #1) id 17BJFr-000DBu-0Z; Fri, 24 May 2002 18:53:32 +0100 Received: from localhost (localhost [127.0.0.1]) by teabag.cbhnet (Postfix) with ESMTP id 94D7E652AB; Fri, 24 May 2002 18:53:29 +0100 (BST) Date: Fri, 24 May 2002 18:53:29 +0100 (BST) From: Chris Hedley X-X-Sender: cbh@teabag.cbhnet To: Mike Barcroft Cc: freebsd-current@freebsd.org Subject: Re: strtod & sscanf on -CURRENT? In-Reply-To: <20020524131550.C26122@espresso.q9media.com> Message-ID: <20020524184214.M3863-100000@teabag.cbhnet> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Fri, 24 May 2002, Mike Barcroft wrote: > Would it be possible for you to reproduce the source to a small > program that demonstrates the problem? Okay, here's a cheap'n'nasty program to demonstrate the problem; the revised problem seems to be that strtod() is okay with integers but if a period is present in the value passed to it, it returns the count of the digits after the period, rather oddly: #include main() { char buf[80], *eol; double a; while(1) { printf("> "); if(!fgets(buf, sizeof buf, stdin) || tolower(buf[0]) == 'q') exit(0); if(eol = strchr(buf, '\n')) *eol = 0; a = strtod(buf, 0); printf("buf=%s val=%7.2f\n", buf, a); } } results: ===> uname -a FreeBSD teabag.cbhnet 5.0-CURRENT FreeBSD 5.0-CURRENT #10: Thu May 16 15:40:46 BST 2002 root@teabag.cbhnet:/usr/obj/usr/src/sys/TEABAG i386 ===> ./a > 324 buf=324 val= 324.00 > 1 buf=1 val= 1.00 > 1.2 buf=1.2 val= 1.00 > 2.1 buf=2.1 val= 1.00 > 22.53 buf=22.53 val= 2.00 > 123.45 buf=123.45 val= 2.00 > 4216.6547 buf=4216.6547 val= 4.00 > 23513.63462 buf=23513.63462 val= 5.00 > 23.53256 buf=23.53256 val= 5.00 > 5432.63426abcde buf=5432.63426abcde val= 5.00 > q Now I'm not discounting that I've overlooked something really obvious or have done something stupid with my test and original programs, but I can't think what it is if this is the case! Chris. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message