Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!decwrl!adobe!tabasco From: hamachi@tabasco (Gordon Hamachi) Newsgroups: comp.sys.next Subject: Re: Yet another bug in the NextStep 2.0 C library. Message-ID: <13738@adobe.UUCP> Date: 8 Apr 91 19:17:42 GMT References: <1991Apr6.212435.4876@ee.ualberta.ca> Sender: news@adobe.COM Lines: 25 Here's a workaround for your problem with strtod(): You can use sscanf() with the %n option to figure out how much of your input has been consumed, and then do pointer arithmetic to get the correct value for ptr. But... The %n option doesn't work correctly when the input string is completely consumed--the corresponding integer arg is not changed. The workaround for THIS problem is to initialize the integer arg to the input string length. It will be changed IFF the input is not completely consumed: int charsUsed=strlen((char *) s; double doubleValue; if(sscanf((char *) s, "%F%n", &doubleValue, &charsUsed)) Eric Norum writes > The strtod supplied with NextStep 2.0 does not behave as expected. > It returns a zero and `ptr' is set to point at the '\0' at the end > of the `trash' string indicating a valid number was converted. > > This is most annoying. I use strtod instead of atof because strtod > is supposed to return an indication of invalid data. Has anyone got > a fix for this?