Why the error does not occur when I put a float number?
int m;
if(scanf("%d%",&m)!=1)
{
printf("Error\n");
exit(1);
}
Why the error does not occur when I put a float number?
int m;
if(scanf("%d%",&m)!=1)
{
printf("Error\n");
exit(1);
}
Because %d will consume all decimal digits until the first non-decimal digit. So if you enter "50.5" m will have the value 50 and the characters ".5" will remain in the buffer unread.
There are many possible solutions. Here's one:
int m ;
double fm ;
if( scanf("%f%",&fm) != 1 ||
modf( fm, &m) != 0 )
{
printf("Error\n");
exit(1);
}