oh my gosh i can't even get isdigit to work
I have tried the most basic of programs and I just cannot get it!
1 2 3 4 5 6 7 8 9 10 11
|
int main(void){
int guess;
scanf("%d", &guess);
if(isdigit(guess)){printf("true");}
system("pause");
return 0;
}
|
This program displays nothing, even when I input a digit such as 5
try add fflush(stdout);
after the call to printf.
1 2 3 4 5 6 7 8 9 10 11 12
|
int main(void){
int guess;
scanf("%d", &guess);
if(isdigit(guess)){printf("true"); fflush(stdout);}
system("pause");
return 0;
}
|
Doesn't work. After I input 5 it just says press any key to quit. I'm running Dev-C++ but it's not working when i compile it under cygwin either.
Oh, now I see. If you input 50 it will print "true" ;)
The problem is that you read in an int value but isdigit works on char values.
ok thanks! I changed it to this and it works now:
1 2 3 4 5 6 7 8 9 10 11 12
|
int main(void){
char guess;
scanf("%c", &guess);
if(isdigit(guess)){printf("true");}
system("pause");
return 0;
}
|
I thought I was going crazy there for a while lol
Topic archived. No new replies allowed.