Trying to use scanf to check i have the right amount of inputs ( in this case 2), and the code works fine, but if i put in 1 input it just keeps waiting for a second, and if i put in 3 it just discards the 3rd, nothing i do will ever return the error message. Have searched for an answer, but not found anything i could use, the reason i ask is the text book i am using for this subject has the code exactly the same as i have it here ( i copied out a different example for int_swap word for word, and it doesn't seem to work either? Any ideas? Sorry if this is a stupid or easy question.
#include <stdlib.h>
#include <stdio.h>
void int_sort2(int*, int*);
int
main(int argc, char* argv[])
{
int x, y;
printf("Please enter 2 numbers : ");
if(scanf("%d%d", &x, &y) != 2)
{
printf("Error in numbers entered\n");
exit(EXIT_FAILURE);
}
printf("The original order was %d, %d\n", x, y);
int_sort2(&x, &y);
printf("The sorted order is : %d, %d\n", x,y);
return 0;
}
void
int_sort2(int *x, int *y)
{
if(*y < *x)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
return;
}
3as a result, it just stops reading once it has gotten 2.