www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/15/07:42:13

Date: Mon, 15 Sep 1997 14:38:59 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: anfamily AT sprintmail DOT com
cc: djgpp AT delorie DOT com
Subject: Re: checking types
In-Reply-To: <341B0CE1.29B0@sprintmail.com>
Message-ID: <Pine.SUN.3.91.970915143827.22620F-100000@is>
MIME-Version: 1.0

On Sat, 13 Sep 1997 anfamily AT sprintmail DOT com wrote:

> How would you check a variable to make sure it's a certain data type you
> want it to be?  I have a small prog, that needs this.  It prompts you
> for an integer, but you can enter other types.  If you enter other
> types, if really screws up the prog.

The simplest yet reliable way I know to deal with input of integer
values is to read it as a string (e.g., with `fgets'), then pass it to
`strtol'.  `strtol' returns a pointer to the first character that is
NOT part of a number.  So, if the user types a number, that pointer
will point right to the terminating null; if it points before that,
yell at the user.

- Raw text -


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