<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'checking for errors using strtod in C' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'checking for errors using strtod in C' posted on the 'C and C++' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Thu, 20 Jun 2013 03:38:53 -0700</pubDate>
    <lastBuildDate>Thu, 20 Jun 2013 03:38:53 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>checking for errors using strtod in C</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/343900/343900/checking-for-errors-using-strtod-in-c/</link>
      <description>Hi,&lt;br /&gt;
Im writing a C program that accepts some values as command line arguments and performs some calculations on them.&lt;br /&gt;
&lt;br /&gt;
I need the strings read form the command line to be converted to float or double (whichever). That's not a problem. Using either atof() or strtof() (or atod() and strtod()) works fine. &lt;br /&gt;
&lt;br /&gt;
My main problem is trying to handle the error if the user does not enter a floating poin value. I read the specification for strtod() to capture errors but i can't make head or tail of it. Could someone please explain how the error checking part of these functions works?&lt;br /&gt;
&lt;br /&gt;
(e.g.: if the user enters "hello" instead of "5.54353" i need to be able to respond and print and error message saying "floating point value not entered".)&lt;br /&gt;
&lt;br /&gt;
Thanks in advance.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/343900/343900/checking-for-errors-using-strtod-in-c/</guid>
      <pubDate>Sun, 27 Aug 2006 21:40:44 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: checking for errors using strtod in C</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/343900/343903/re-checking-for-errors-using-strtod-in-c/#343903</link>
      <description>: Hi,&lt;br /&gt;
: Im writing a C program that accepts some values as command line arguments and performs some calculations on them.&lt;br /&gt;
: &lt;br /&gt;
: I need the strings read form the command line to be converted to float or double (whichever). That's not a problem. Using either atof() or strtof() (or atod() and strtod()) works fine. &lt;br /&gt;
: &lt;br /&gt;
: My main problem is trying to handle the error if the user does not enter a floating poin value. I read the specification for strtod() to capture errors but i can't make head or tail of it. Could someone please explain how the error checking part of these functions works?&lt;br /&gt;
: &lt;br /&gt;
: (e.g.: if the user enters "hello" instead of "5.54353" i need to be able to respond and print and error message saying "floating point value not entered".)&lt;br /&gt;
: &lt;br /&gt;
: Thanks in advance.&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
This is what I could make out of the man page:&lt;br /&gt;
&lt;br /&gt;
char a[100];&lt;br /&gt;
char *sp = a, **ep = a+100&lt;br /&gt;
double b;&lt;br /&gt;
scanf("%s");&lt;br /&gt;
b=strtod(a,sp,ep);&lt;br /&gt;
if(b==0&amp;amp;&amp;amp;sp==*ep)&lt;br /&gt;
    printf("error");&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/343900/343903/re-checking-for-errors-using-strtod-in-c/#343903</guid>
      <pubDate>Sun, 27 Aug 2006 23:05:55 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: checking for errors using strtod in C</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/343900/343909/re-checking-for-errors-using-strtod-in-c/#343909</link>
      <description>: : Hi,&lt;br /&gt;
: : Im writing a C program that accepts some values as command line arguments and performs some calculations on them.&lt;br /&gt;
: : &lt;br /&gt;
: : I need the strings read form the command line to be converted to float or double (whichever). That's not a problem. Using either atof() or strtof() (or atod() and strtod()) works fine. &lt;br /&gt;
: : &lt;br /&gt;
: : My main problem is trying to handle the error if the user does not enter a floating poin value. I read the specification for strtod() to capture errors but i can't make head or tail of it. Could someone please explain how the error checking part of these functions works?&lt;br /&gt;
: : &lt;br /&gt;
: : (e.g.: if the user enters "hello" instead of "5.54353" i need to be able to respond and print and error message saying "floating point value not entered".)&lt;br /&gt;
: : &lt;br /&gt;
: : Thanks in advance.&lt;br /&gt;
: : &lt;br /&gt;
: &lt;br /&gt;
: This is what I could make out of the man page:&lt;br /&gt;
: &lt;br /&gt;
: char a[100];&lt;br /&gt;
: char *sp = a, **ep = a+100&lt;br /&gt;
: double b;&lt;br /&gt;
: scanf("%s");&lt;br /&gt;
: b=strtod(a,sp,ep);&lt;br /&gt;
: if(b==0&amp;amp;&amp;amp;sp==*ep)&lt;br /&gt;
:     printf("error");&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There seems to be a lot of error handling surrounding those strto.. functions. This is what ANSI C says to explain the code posted by IDK:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
double strtod(const char * restrict nptr, char ** restrict endptr);

/--/

If the subject sequence is empty or does not have the expected form, 
no conversion is performed; the value of nptr is stored in the object
pointed to by endptr, provided that endptr is not a null pointer.
&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/343900/343909/re-checking-for-errors-using-strtod-in-c/#343909</guid>
      <pubDate>Sun, 27 Aug 2006 23:47:13 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: checking for errors using strtod in C</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/343900/343911/re-checking-for-errors-using-strtod-in-c/#343911</link>
      <description>: &lt;br /&gt;
: There seems to be a lot of error handling surrounding those strto.. functions. This is what ANSI C says to explain the code posted by IDK:&lt;br /&gt;
: &lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
: double strtod(const char * restrict nptr, char ** restrict endptr);
: 
: /--/
: 
: If the subject sequence is empty or does not have the expected form, 
: no conversion is performed; the value of nptr is stored in the object
: pointed to by endptr, provided that endptr is not a null pointer.
: &lt;/pre&gt;&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
Ops, made an err...&lt;br /&gt;
&lt;br /&gt;
Here's the corrected version:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
char a[100];
char **ep = a+100
double b;
scanf("%s");
b=strtod(a,ep);
if(b==0&amp;amp;&amp;amp;a==*ep)
    printf("error");
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is what the man page says:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
       double strtod(const char *nptr, char **endptr);

...

RETURN VALUE
       These functions return the converted value, if any.

       If endptr is not NULL, a pointer to the character after the last char-
       acter used in the conversion is stored in the location  referenced  by
       endptr.

       If  no conversion is performed, zero is returned and the value of nptr
       is stored in the location referenced by endptr.

       If the correct value would cause  overflow,  plus  or  minus  HUGE_VAL
       (HUGE_VALF,  HUGE_VALL)  is  returned  (according  to  the sign of the
       value), and ERANGE is stored in errno.  If  the  correct  value  would
       cause underflow, zero is returned and ERANGE is stored in errno.
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
A little more complex, and without the restrict qualifier (never seen it before).&lt;br /&gt;
&lt;br /&gt;
Also, this was listed a little below:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
CONFORMING TO
       ANSI C describes strtod, C99 describes the other two functions.
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Where the other two funcs are strof and strtold.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/343900/343911/re-checking-for-errors-using-strtod-in-c/#343911</guid>
      <pubDate>Mon, 28 Aug 2006 00:11:56 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: checking for errors using strtod in C</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/343900/343912/re-checking-for-errors-using-strtod-in-c/#343912</link>
      <description>: : &lt;br /&gt;
: : There seems to be a lot of error handling surrounding those strto.. functions. This is what ANSI C says to explain the code posted by IDK:&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;pre class="sourcecode"&gt;
: : double strtod(const char * restrict nptr, char ** restrict endptr);
: : 
: : /--/
: : 
: : If the subject sequence is empty or does not have the expected form, 
: : no conversion is performed; the value of nptr is stored in the object
: : pointed to by endptr, provided that endptr is not a null pointer.
: : &lt;/pre&gt;&lt;br /&gt;
: : &lt;br /&gt;
: &lt;br /&gt;
: Ops, made an err...&lt;br /&gt;
: &lt;br /&gt;
: Here's the corrected version:&lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
: char a[100];
: char **ep = a+100
: double b;
: scanf("%s");
: b=strtod(a,ep);
: if(b==0&amp;amp;&amp;amp;a==*ep)
:     printf("error");
: &lt;/pre&gt;&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: This is what the man page says:&lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
:        double strtod(const char *nptr, char **endptr);
: 
: ...
: 
: RETURN VALUE
:        These functions return the converted value, if any.
: 
:        If endptr is not NULL, a pointer to the character after the last char-
:        acter used in the conversion is stored in the location  referenced  by
:        endptr.
: 
:        If  no conversion is performed, zero is returned and the value of nptr
:        is stored in the location referenced by endptr.
: 
:        If the correct value would cause  overflow,  plus  or  minus  HUGE_VAL
:        (HUGE_VALF,  HUGE_VALL)  is  returned  (according  to  the sign of the
:        value), and ERANGE is stored in errno.  If  the  correct  value  would
:        cause underflow, zero is returned and ERANGE is stored in errno.
: &lt;/pre&gt;&lt;br /&gt;
: &lt;br /&gt;
: A little more complex, and without the restrict qualifier (never seen it before).&lt;br /&gt;
: &lt;br /&gt;
: Also, this was listed a little below:&lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
: CONFORMING TO
:        ANSI C describes strtod, C99 describes the other two functions.
: &lt;/pre&gt;&lt;br /&gt;
: &lt;br /&gt;
: Where the other two funcs are strof and strtold.&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I posted only the relevant part of the description, the whole text is 2 pages. restrict is a C99 invention, if I remember correctly it is there to prevent several pointers to mess around with the same memory location. When implementing memcpy() for example:&lt;br /&gt;
&lt;br /&gt;
void *memcpy(void * restrict s1, const void * restrict s2, size_t n);&lt;br /&gt;
&lt;br /&gt;
The compiler manufacturer can be sure that s1 and s2 aren't pointing at the same memory location, and therefore make the function more efficient.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/343900/343912/re-checking-for-errors-using-strtod-in-c/#343912</guid>
      <pubDate>Mon, 28 Aug 2006 00:22:45 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: checking for errors using strtod in C</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/343900/343913/re-checking-for-errors-using-strtod-in-c/#343913</link>
      <description>: &lt;br /&gt;
: I posted only the relevant part of the description.&lt;br /&gt;
&lt;br /&gt;
Me to, the whole text is about 4 pages.&lt;br /&gt;
I think the overflow checking is very relevant.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And the main reason I posted it was that I found this strange:&lt;br /&gt;
Ansi C: double strtod(const char * restrict nptr, char ** restrict ndptr);&lt;br /&gt;
Man (C99): double strtod(const char *nptr, char **endptr);&lt;br /&gt;
&lt;br /&gt;
This means that this could happen (becouse memcpy is defined void *memcpy(void *dest, const void *src, size_t n)):&lt;br /&gt;
memcpy(a,a);&lt;br /&gt;
And that would be bad...&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/343900/343913/re-checking-for-errors-using-strtod-in-c/#343913</guid>
      <pubDate>Mon, 28 Aug 2006 01:34:11 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: checking for errors using strtod in C</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/343900/343914/re-checking-for-errors-using-strtod-in-c/#343914</link>
      <description>Note that C99 is just a draft standard and not many compilers support it. Correct me if I'm wrong, but I doubt that 'man' would refer to C99?&lt;br /&gt;
&lt;br /&gt;
: memcpy(a,a);&lt;br /&gt;
&lt;br /&gt;
Yep, that is undefined behaviour in "classic" C. In C99 I believe you would get a compiler error. But imo, the programmer that writes memcpy() to copy "source" to the same location as "destination" will have to suit themselves, because then they have likely got a bug in the code.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/343900/343914/re-checking-for-errors-using-strtod-in-c/#343914</guid>
      <pubDate>Mon, 28 Aug 2006 01:49:32 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: checking for errors using strtod in C</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/343900/343915/re-checking-for-errors-using-strtod-in-c/#343915</link>
      <description>&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by IDK at  2006-8-28 2:43:22&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: Note that C99 is just a draft standard and not many compilers support it. Correct me if I'm wrong, but I doubt that 'man' would refer to C99?&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
man refers to, as listed before:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
man strtod:
CONFORMING TO
       ANSI C describes strtod, C99 describes the other two functions.

man memcpy:
CONFORMING TO
       SVID 3, BSD 4.3, ISO 9899
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
: : memcpy(a,a);&lt;br /&gt;
: &lt;br /&gt;
: Yep, that is undefined behaviour in "classic" C. In C99 I believe you would get a compiler error. But imo, the programmer that writes memcpy() to copy "source" to the same location as "destination" will have to suit themselves, because then they have likely got a bug in the code.&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
memcpy(a,a+1); should also give compile error, but it could be usefull.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/343900/343915/re-checking-for-errors-using-strtod-in-c/#343915</guid>
      <pubDate>Mon, 28 Aug 2006 02:42:33 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: checking for errors using strtod in C</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/343900/343926/re-checking-for-errors-using-strtod-in-c/#343926</link>
      <description>: &lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by IDK at  2006-8-28 2:43:22&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: : Note that C99 is just a draft standard and not many compilers support it. Correct me if I'm wrong, but I doubt that 'man' would refer to C99?&lt;br /&gt;
: : &lt;br /&gt;
: &lt;br /&gt;
: man refers to, as listed before:&lt;br /&gt;
: &lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
: man strtod:
: CONFORMING TO
:        ANSI C describes strtod, C99 describes the other two functions.
: 
: man memcpy:
: CONFORMING TO
:        SVID 3, BSD 4.3, ISO 9899
: &lt;/pre&gt;&lt;br /&gt;
: &lt;br /&gt;
: : : memcpy(a,a);&lt;br /&gt;
: : &lt;br /&gt;
: : Yep, that is undefined behaviour in "classic" C. In C99 I believe you would get a compiler error. But imo, the programmer that writes memcpy() to copy "source" to the same location as "destination" will have to suit themselves, because then they have likely got a bug in the code.&lt;br /&gt;
: : &lt;br /&gt;
: &lt;br /&gt;
: memcpy(a,a+1); should also give compile error, but it could be usefull.&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
What about memmove()?&lt;br /&gt;
{2}rIng&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/343900/343926/re-checking-for-errors-using-strtod-in-c/#343926</guid>
      <pubDate>Mon, 28 Aug 2006 05:45:02 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: checking for errors using strtod in C</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/343900/343979/re-checking-for-errors-using-strtod-in-c/#343979</link>
      <description>&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by Lundin at  2006-8-28 23:35:12&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: : &lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by IDK at  2006-8-28 2:43:22&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: : : Note that C99 is just a draft standard and not many compilers support it. Correct me if I'm wrong, but I doubt that 'man' would refer to C99?&lt;br /&gt;
: : : &lt;br /&gt;
: : &lt;br /&gt;
: : man refers to, as listed before:&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;pre class="sourcecode"&gt;
: : man strtod:
: : CONFORMING TO
: :        ANSI C describes strtod, C99 describes the other two functions.
: : 
: : man memcpy:
: : CONFORMING TO
: :        SVID 3, BSD 4.3, ISO 9899
: : &lt;/pre&gt;&lt;br /&gt;
: : &lt;br /&gt;
: : : : memcpy(a,a);&lt;br /&gt;
: : : &lt;br /&gt;
: : : Yep, that is undefined behaviour in "classic" C. In C99 I believe you would get a compiler error. But imo, the programmer that writes memcpy() to copy "source" to the same location as "destination" will have to suit themselves, because then they have likely got a bug in the code.&lt;br /&gt;
: : : &lt;br /&gt;
: : &lt;br /&gt;
: : memcpy(a,a+1); should also give compile error, but it could be usefull.&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: &lt;br /&gt;
: What about memmove()?&lt;br /&gt;
: {2}rIng&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
memmove() is almost the same thing as memcpy() : it is safer, but not as fast. Should be identical in C90 and C99:&lt;br /&gt;
&lt;br /&gt;
7.21.2.2 The memmove function&lt;br /&gt;
&lt;br /&gt;
Synopsis&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
void *memmove(void *s1, const void *s2, size_t n);&lt;br /&gt;
&lt;br /&gt;
Description&lt;br /&gt;
The memmove function copies n characters from the object pointed to by&lt;br /&gt;
s2 into the object pointed to by s1. Copying takes place as if the n &lt;br /&gt;
characters from the object pointed to by s2 are first copied into a &lt;br /&gt;
temporary array of n characters that does not overlap the objects &lt;br /&gt;
pointed to by s1 and s2, and then the n characters from the temporary array are copied into the object pointed to by s1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/343900/343979/re-checking-for-errors-using-strtod-in-c/#343979</guid>
      <pubDate>Mon, 28 Aug 2006 23:34:31 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: checking for errors using strtod in C</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/343900/344006/re-checking-for-errors-using-strtod-in-c/#344006</link>
      <description>: Here's the corrected version:&lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
: char a[100];
: char **ep = a+100
: double b;
: scanf("%s");
: b=strtod(a,ep);
: if(b==0&amp;amp;&amp;amp;a==*ep)
:     printf("error");
: &lt;/pre&gt;&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: This is what the man page says:&lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
:        double strtod(const char *nptr, char **endptr);
: 
: ...
: 
: RETURN VALUE
:        These functions return the converted value, if any.
: 
:        If endptr is not NULL, a pointer to the character after the last char-
:        acter used in the conversion is stored in the location  referenced  by
:        endptr.
: 
:        If  no conversion is performed, zero is returned and the value of nptr
:        is stored in the location referenced by endptr.
: 
:        If the correct value would cause  overflow,  plus  or  minus  HUGE_VAL
:        (HUGE_VALF,  HUGE_VALL)  is  returned  (according  to  the sign of the
:        value), and ERANGE is stored in errno.  If  the  correct  value  would
:        cause underflow, zero is returned and ERANGE is stored in errno.
: &lt;/pre&gt;&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
Sorry if this seems like a stupid question, but I always get confused with pointers (as a lot of people do).&lt;br /&gt;
Why is endptr a **, and not just a *?&lt;br /&gt;
&lt;br /&gt;
Best Regards,&lt;br /&gt;
Richard&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/343900/344006/re-checking-for-errors-using-strtod-in-c/#344006</guid>
      <pubDate>Tue, 29 Aug 2006 08:28:00 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: checking for errors using strtod in C</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/343900/344010/re-checking-for-errors-using-strtod-in-c/#344010</link>
      <description>: Sorry if this seems like a stupid question, but I always get confused with pointers (as a lot of people do).&lt;br /&gt;
: Why is endptr a **, and not just a *?&lt;br /&gt;
: &lt;br /&gt;
: Best Regards,&lt;br /&gt;
: Richard&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
So it can return a pointer...&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
a(char *a){
    a=" "; //error
}

a(char **a){
    *a=" "; //OK
}
&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/343900/344010/re-checking-for-errors-using-strtod-in-c/#344010</guid>
      <pubDate>Tue, 29 Aug 2006 08:53:45 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: checking for errors using strtod in C</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/343900/344014/re-checking-for-errors-using-strtod-in-c/#344014</link>
      <description>: : Sorry if this seems like a stupid question, but I always get confused with pointers (as a lot of people do).&lt;br /&gt;
: : Why is endptr a **, and not just a *?&lt;br /&gt;
: : &lt;br /&gt;
: : Best Regards,&lt;br /&gt;
: : Richard&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: &lt;br /&gt;
: So it can return a pointer...&lt;br /&gt;
: &lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
: a(char *a){
:     a=" "; //error
: }
: 
: a(char **a){
:     *a=" "; //OK
: }
: &lt;/pre&gt;&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
Reading through the documentation again makes more sense.&lt;br /&gt;
It writes a {pointer to a char} to the location specified by endptr.&lt;br /&gt;
But that leaves me to wonder if your code, where you set endptr to a+100, is right. Aren't you then telling the function to write to a[100], which is unreserved memory?&lt;br /&gt;
&lt;br /&gt;
Darn, I managed to confuse myself with another question:&lt;br /&gt;
How much memory would have to be reserved for the location pointed to by ep? I'm guessing the standard pointer size (= 4 bytes?), rather than 1 byte (=char), but doubting if I am correct :-S&lt;br /&gt;
&lt;br /&gt;
Best Regards,&lt;br /&gt;
Richard&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/343900/344014/re-checking-for-errors-using-strtod-in-c/#344014</guid>
      <pubDate>Tue, 29 Aug 2006 09:12:19 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: checking for errors using strtod in C</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/343900/344018/re-checking-for-errors-using-strtod-in-c/#344018</link>
      <description>: Reading through the documentation again makes more sense.&lt;br /&gt;
: It writes a {pointer to a char} to the location specified by endptr.&lt;br /&gt;
: But that leaves me to wonder if your code, where you set endptr to a+100, is right. Aren't you then telling the function to write to a[100], which is unreserved memory?&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
Yeah I know, but that did just fall out of my mind...&lt;br /&gt;
&lt;br /&gt;
: Darn, I managed to confuse myself with another question:&lt;br /&gt;
: How much memory would have to be reserved for the location pointed to by ep? I'm guessing the standard pointer size (= 4 bytes?), rather than 1 byte (=char), but doubting if I am correct :-S&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
Since it's a pointer ep should be defined like this:&lt;br /&gt;
char *ep;&lt;br /&gt;
And then use &amp;amp;ep as a parameter...&lt;br /&gt;
&lt;br /&gt;
And yes, since it's defined as a pointer it is a pointer, and thus have the size sizeof(int) wich on 32 bit systems is 4 bytes (but I may be wrong here).&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/343900/344018/re-checking-for-errors-using-strtod-in-c/#344018</guid>
      <pubDate>Tue, 29 Aug 2006 10:05:51 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: checking for errors using strtod in C</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/343900/344048/re-checking-for-errors-using-strtod-in-c/#344048</link>
      <description>: : Reading through the documentation again makes more sense.&lt;br /&gt;
: : It writes a {pointer to a char} to the location specified by endptr.&lt;br /&gt;
: : But that leaves me to wonder if your code, where you set endptr to a+100, is right. Aren't you then telling the function to write to a[100], which is unreserved memory?&lt;br /&gt;
: : &lt;br /&gt;
: &lt;br /&gt;
: Yeah I know, but that did just fall out of my mind...&lt;br /&gt;
: &lt;br /&gt;
: : Darn, I managed to confuse myself with another question:&lt;br /&gt;
: : How much memory would have to be reserved for the location pointed to by ep? I'm guessing the standard pointer size (= 4 bytes?), rather than 1 byte (=char), but doubting if I am correct :-S&lt;br /&gt;
: : &lt;br /&gt;
: &lt;br /&gt;
: Since it's a pointer ep should be defined like this:&lt;br /&gt;
: char *ep;&lt;br /&gt;
: And then use &amp;amp;ep as a parameter...&lt;br /&gt;
: &lt;br /&gt;
: And yes, since it's defined as a pointer it is a pointer, and thus have the size sizeof(int) wich on 32 bit systems is 4 bytes (but I may be wrong here).&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
It has the sizeof(void*), rather... which happens to be 4 bytes on 32bit &lt;img src="http://www.programmersheaven.com/images/Community/smile.gif" width="15" height="15" alt="" /&gt;&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/343900/344048/re-checking-for-errors-using-strtod-in-c/#344048</guid>
      <pubDate>Tue, 29 Aug 2006 23:58:18 -0700</pubDate>
      <category>C and C++</category>
    </item>
  </channel>
</rss>