Mail Archives: djgpp/1999/09/04/14:52:49
From: | Martin Ambuhl <mambuhl AT earthlink DOT net>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: how to use atof?
|
Date: | Sat, 04 Sep 1999 13:03:43 -0400
|
References: | <7qr9uh$3fk$1 AT thetenth DOT astat DOT de>
|
X-Posted-Path-Was: | not-for-mail
|
X-Accept-Language: | en
|
X-ELN-Date: | 4 Sep 1999 17:01:54 GMT
|
X-ELN-Insert-Date: | Sat Sep 4 10:05:25 1999
|
Organization: | Nocturnal Aviation
|
Lines: | 54
|
Mime-Version: | 1.0
|
NNTP-Posting-Host: | dialup-209.246.77.162.newyork2.level3.net
|
Message-ID: | <37D150EF.420FADC3@earthlink.net>
|
X-Mailer: | Mozilla 4.61 [en] (Win95; U)
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Berti Drost wrote:
>
> Hello,
> I have some troubles useing the command atof (convert string to double);
> the following code isn't produceing the correct results. Can anybody tell me
> what the mistake might be? (It occures also, if I use strtod; on the other
> hand, atoi (convert str to integer) is working perfectly:-( )
>
> int main(int argc, char *argv)
> {
> char *zahl="153.34";
> char *err;
> double out_f;
> out_f=atof(zahl);
> // out_f=strtod(zahl,&err);
> printf("strtod() : %f\n",out_f);
> printf("err=%c\n",*err);
> return(0);
> }
If this is your actual code, the only problems are the failure to
#include required headers, an incorrect argument to main(), and the
attempt to derefernece a wild pointer/ See what happens with this code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char *zahl = "153.34";
char *err = 0;
double out_f;
out_f = atof(zahl);
printf("atof() : %f\n", out_f);
out_f = strtod(zahl, &err);
printf("strtod() : %f\n", out_f);
if (err) printf("err=%c\n", *err);
return (0);
}
atof() : 153.340000
strtod() : 153.340000
err=
--
Martin Ambuhl mambuhl AT earthlink DOT net
__________________________________________________________
Fight spam now!
Get your free anti-spam service: http://www.brightmail.com
- Raw text -