Message-Id: <199709142333.SAA08714@fly.HiWAAY.net> Reply-To: From: "Kurt Wall" To: Cc: Subject: Re: checking types Date: Sun, 14 Sep 1997 18:32:21 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Precedence: bulk I presume you are using C. This is only one of many problems with scanf. The "standard" (that is, usual) approach is to read an entire line using fgets() (see your docs), then scan through the string using isdigit() and such (not ANSI-standard, I think). Another approach is to use getch() to read character input one character at a time, then use the ANSI conversion functions to turn the input into something useful. For example: #include #define LIMIT 100 int i, c; char num[limit]; main() { i = 0; /* read characters from stdin until * 1) we get an EOF * 2) a newline * 3) approach the buffer limit */ while((c=getchar()) != EOF && c != '\n' && i < LIMIT - 1) { /* if the input is numeric, store it */ if(c >= '0' && c <= '9') { num[i] = c; i++; } if(c == '\n') num[i] = '\0'; i = atoi(num); if(num != 0) printf("%d\n", num); return 0; } ---------- > From: anfamily AT sprintmail DOT com > To: djgpp AT delorie DOT com > Subject: checking types > Date: Saturday, September 13, 1997 5:00 PM > > 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. I'm using a scanf to get that > value for a variable, but after that, I want to check to make sure the > value in that variable is a integer. If it's not, it would prompt the > user again. How would I do that? > -- > (~_Ionicis_~) > http://www.geocities.com/SiliconValley/Bay/2306/ <--- Go here!