I was trying to figure out how to check if input given by the user is an integer. I tried for a while and failed, until today my teacher showed me a cool trick. In c, you can get a return value from the scanf function like this(returns a 0 if it's false, and a 1 if it's true) hope this helps someone!!:
#include <stdio.h>
int main(void)
{
int inputStatus;
char input;
printf("Please enter an integer\n");
inputStatus = scanf("%d",&input);
printf("%d\n",inputStatus);
system("pause");
}
Edited by ApprentiC, 10 February 2011 - 06:59 PM.


Sign In
Create Account

Back to top









