Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 May 2002 18:53:29 +0100 (BST)
From:      Chris Hedley <cbh@teabag.demon.co.uk>
To:        Mike Barcroft <mike@freebsd.org>
Cc:        freebsd-current@freebsd.org
Subject:   Re: strtod & sscanf on -CURRENT?
Message-ID:  <20020524184214.M3863-100000@teabag.cbhnet>
In-Reply-To: <20020524131550.C26122@espresso.q9media.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <stdio.h>

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020524184214.M3863-100000>