www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/05/10:48:16

From: Eyal Ben-David <eyal DOT ben-david AT aks DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Testing for float or int
Date: Tue, 05 May 1998 17:47:24 +0300
Organization: AKS
Lines: 20
Message-ID: <354F267C.2B85@aks.com>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 980503175458 DOT 19706R-100000 AT is>
NNTP-Posting-Host: pathfinder.aladdin.co.il
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Eli Zaretskii wrote:
> 
> On Thu, 30 Apr 1998, Oon Lin wrote:
> 
> > I had been surfing around Delorie's lib C online reference for a
> > function that can test whether an input is in float or int.
> 
> One way of doing this is to call the functions `strtod' and `strtol'
> on a string that's supposed to be the number and nothing else.  These
> functions return a pointer to after the last character of the string
> that is still part of a legal number.  So if that pointer points to
> the terminating '\0' character, the entire number is in correct
> format.
> 
> Since every int can be read as a double, but not the other way around,
> calling `strtol' alone should supply the desired result.

And don't forget to check errno for ERANGE

Eyal.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019