Date: Thu, 29 Jul 1999 11:03:50 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: Dan Gold 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: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk 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.