Okay, I have to somehow check an integer value for a character or punctuation character. The catch is that the variable has already been read in; therefor I cannot use getch() or.. can I???
Okay, as you can see below, I read in a value and store it as a float, after I store it as a float, I check and see if it is actually a float (double) value. If it is .0, then I know it is an integer so I convert the float to an integer and return 0 to main() to let it know that the user has entered a valid integer.
currently I have the following which checks for float values and it works as long as a period is not entered or a character is not entered. Any ideas ? Suggestions? Again, the value is set and I cannot use getch unless I can take it from a pre-assigned variable.
Code:
int input_validate() {
int guess;
double temp=12,temp2,i_part;
temp2=temp;
if (modf(temp,&i_part)>0.) /* Checks for a double value */
return -1;
else {
guess=(int)temp2; /*Stores the temp value into guess as Integer */
if ((guess<100)&&(guess>=0))
return 1;
else
return -1;
}
}
Any ideas how i can check for chars and punctuation??? Thanks.