delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/03/10:57:12

Date: Sun, 3 May 1998 17:55:16 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Oon Lin <Oon DOT Lin AT jcu DOT edu DOT au>
cc: djgpp AT delorie DOT com
Subject: Re: Testing for float or int
In-Reply-To: <35481B84.167E@jcu.edu.au>
Message-ID: <Pine.SUN.3.91.980503175458.19706R-100000@is>
MIME-Version: 1.0

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.

- Raw text -


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