Subject: atof or finger problem ?
To: None <netbsd-help@netbsd.org>
From: Claude Marinier <claude.marinier@dreo.dnd.ca>
List: netbsd-help
Date: 09/18/2001 16:01:54
Hi,
This seems simple but the result is obviously wrong. I may be too tired
and making stupid mistakes.
Got it! I forgot to include stdlib.h but why did it not complain that atof
was implicitely defined? Instead, it quietly does the wrong thing.
#include <stdio.h>
#include <math.h>
int main( int argc, char *argv[] )
{
double x; /* the decimal */
argc--; argv++; /* skip command name */
if ( argc == 0 ) {
return 1;
}
if ( argc == 1 ) {
printf ( "argv[0] is \"%s\"\n", argv[0] );
x = atof( argv[0] );
} else {
return 1;
}
printf ( "x = %10.8f\n", x ); /* */
return 0;
}
Result is
argv[0] is "0.123"
x = 3.00000000
--
Claude Marinier, Information Technology Group claude.marinier@dreo.dnd.ca
Defence Research Establishment Ottawa (DREO) (613) 998-4901 FAX 998-2675
3701 Carling Avenue, Ottawa, Ontario K1A 0Z4 http://www.dreo.dnd.ca