Date: Mon, 15 Sep 1997 14:38:59 +0300 (IDT) From: Eli Zaretskii 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: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk 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.