delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/29/16:02:49

Date: Thu, 29 Jul 1999 11:03:50 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Dan Gold <TedMat AT CoastNet DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Detecting a 0 and also a letter in atoi()
In-Reply-To: <199907281320.JAA24759@delorie.com>
Message-ID: <Pine.SUN.3.91.990729110332.25908H-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Tue, 26 Jan 1999, Dan Gold wrote:

> Could be offtopic, but It I want to detect if there is a letter in my
> character boxes but atoi returns zero if there is a letter. This is poorly
> designed because I can't use the number 0 when converting the integer
> string to an int variable.

`atoi' is one of the oldest functions in standard C libraries, so it
has to be compatible with its original design, since there are gobs of
programs out there which rely on this behavior.

If you need a conversion function that will also tell you when the
string is not a number, use `strtol'.  It returns a pointer to the
first character in the string that it couldn't convert.  If this
pointer points to something other than the terminating null character,
you know there's a non-digit in the input string.

- Raw text -


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