Whenever I run this segment of my code, if I input anything but a number, it continues looping and prints many "Please enter a number" without stopping to prompt another input. Is scanf
somehow reading what printf
is printing?
int size;
printf("How many numbers would you like to store?\n"); while(1) {
if(scanf("%d", &size)) {
printf("WORKING\n");
break;
}
else {
printf("Please enter a number\n");
}
The code is meant to only accept an integer as an input, but for some reason when you input something but an integer it continues to loop without another prompt.