linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "James Stevenson" <james@stev.org>
To: linux-c-programming@vger.kernel.org
Subject: RE: strtod() and errno question.
Date: Tue, 10 Jan 2006 22:34:31 -0000	[thread overview]
Message-ID: <000601c61636$065b2740$6a00ac0a@hughesit.local> (raw)
In-Reply-To: <Pine.LNX.4.21.0601102235490.1799-100000@hestia>

Hi,

Try taking a copy of errno before calling fprintf.
See if that helps any.

	James

> -----Original Message-----
> From: linux-c-programming-owner@vger.kernel.org [mailto:linux-c-
> programming-owner@vger.kernel.org] On Behalf Of J.
> Sent: 10 January 2006 21:43
> To: linux-c-programming@vger.kernel.org
> Subject: strtod() and errno question.
> 
> Tuesday, January 10 22:35:50
> 
> Hi people,
> 
> I have a question regarding errno and strtod() error checking. I have a
> function [listed below] that extracts a number from a string. In case of
> an error, strerror() in conjunction with errno is used to display a user
> friendly error message. However on a strtod() error; `Success' is
> returned.
> 
> Error - strtod(ca4)`c': Success
> 
> Since I am a bit confused by the strtod() manual page, what would be the
> correct way to handle this ?
> 
> Thankx !
> 
> J.
> 
> int extrnumber(char *str) {
>  int retv = 0;
>  char *nptr = NULL;
> 
>  retv = strtod(str, &nptr);
>  if(retv == 0 && nptr != NULL) {
>   fprintf(stderr, "%s: Error - strtod(%s)`%c': %s\n", PACKAGE,
>     str, *nptr, strerror(errno));
>   exit(EXIT_FAILURE);
>  }
> 
>  return retv;
> }
> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-
> programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



  reply	other threads:[~2006-01-10 22:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-10 21:42 strtod() and errno question J.
2006-01-10 22:34 ` James Stevenson [this message]
2006-01-11  3:01 ` Glynn Clements
2006-01-11 11:24   ` J.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000601c61636$065b2740$6a00ac0a@hughesit.local' \
    --to=james@stev.org \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).