From: Eyal Ben-David 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: NNTP-Posting-Host: pathfinder.aladdin.co.il Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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.