It is not clear what your problem is. What error do you expect?
You need to tidy up your code. There are few things. scanf
returns int
value - the number of input items assigned. You assign the return value to char x
. Then you assign the input value to x
. What is the logic behind? What do you expect? I guess your problem is logical. I suggest you:
- Handle the return and the input values separately
- Remove
exit()
statement, use return value instead.exit()
terminates the program. - Remove globals
- If the above doesn't help use
printf
to see what is being processed
Example:
int main(void) {
printf("Enter a number in between [10 -100]:\n");
int userIn;
int x = scanf("%d", &userIn);
// for debug
printf("Scanned: %d, returned: %d", x, userIn);
int result = intGet(x, userIn);
// analyse the result here
switch (result) {
case RES_SUCCESS:
return SUCCESS;
case ...
}
}
int intGet(int x, int value) {
int const min = 10;
int const max = 100;
if (x != 1) {
return RES_ERROR_NO_INPUT;
}
if (value < min || value > max) {
return RES_ERROR_OUT_OF_RANGE;
}
return RES_SUCCESS;
}