It may sound like an XY Problem but I am confused.
I want to execute some code when the user enters 6. First have a look at code:
#include<stdio.h>
int main(void) {
short int x;
printf("Val :");
scanf("%d", &x);
if (x == 6) {
//some code
}
return 0;
}
SHRT_MAX
in my system is 32767 and if the user manages to enter 65442 this will be converted to 6 ultimately and the code will be executed at this value while it was supposed to execute at 6. Well, it is getting executed at 6 but from the user's point of view it is the lack of security. Yeah, I can use int
or long int
, but if the user is cracking short int
, it is not the right choice. How can I deal with this issue?