The reason that you are getting infinite loop on entering a non-digit is the non-digit character left in the buffer as it is not read by the scanf
for the next read of scanf
(as it doesn't matches the format specifier). on next iteration scanf
again finds this character and do not read it and exit immediately. This happens repeatedly and you are getting an infinite loop. Place a while(getchar() != '\n');
statement to consume this character.
Try this
#include <stdio.h>
int main(int argc, const char * argv[]) {
int number = 0, isnumber;
getagin: printf("Please enter a number:\n");
isnumber = scanf("%i", &number);
if(isnumber) {
printf("You enterd a number and it was %i\n", number);
} else {
printf("You did not eneter a number.\n");
while(getchar() != '\n'); // T consume all non-digits
goto getagin;
}
return 0;
}