0

I'm trying to check if a number is an integer (num).

In the main() -

int num, input;
    printf("Please enter an integer greater than 1:\n");
        input = scanf("%d",&num);
        if ( input != 1 ){
            printf("Invalid input!\n");
            return 1;
        } 

but when the input is not an integer (33.3 for example), the value of "input" is still 1.

printf("%d ", input);

gives me back 1.

The rest of the program works. Just got stuck on this minor thing.

sheldonzy
  • 5,505
  • 9
  • 48
  • 86

1 Answers1

1

You are going to need to read the input into a char[], (so, no scanf() necessary, you can just do gets() or something similar,) and then check the value yourself, digit by digit, using isdigit().

Mike Nakis
  • 56,297
  • 11
  • 110
  • 142