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 [EMAIL PROTECTED]:/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 [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message