delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/03/14/14:08:33

From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: checking int
Date: Tue, 14 Mar 2000 19:04:00 +0200
Organization: NetVision Israel
Lines: 13
Message-ID: <38CE7100.D3BAF2F9@is.elta.co.il>
References: <8alfpb$fle$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE>
NNTP-Posting-Host: ras1-p111.rvt.netvision.net.il
Mime-Version: 1.0
X-Trace: news.netvision.net.il 953053342 6748 62.0.172.113 (14 Mar 2000 17:02:22 GMT)
X-Complaints-To: abuse AT netvision DOT net DOT il
NNTP-Posting-Date: 14 Mar 2000 17:02:22 GMT
X-Mailer: Mozilla 4.7 [en] (Win98; I)
X-Accept-Language: en,ru,hebrew
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Florent wrote:
> 
> Hi,
> I don't find the way to check if the input I give to the function scanf is
> an int or a char. For example you ask to enter an int, and if a char is
> entered -> BUG, so I need something to check if tne input is an int.
> It's easy to check if it's a char, but int .... I didn't find.

One handy technique is to read the input as a character string, and then
convert it to an int by calling library function `strtol'.  This function
stops at the first non-numeric character and returns to you the pointer to
that character.  If the pointer doesn't point to the '\0' character which
terminates the string, you know that some of the input was not numeric.

- Raw text -


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