My program is supposed to take in an interger, and tell me if it's a prime number or not. If I enter something like "woof", it'll tell me that it is invalid and does not work.
My program is as follows:
When I try to compile it, the printf statement works, but if I try a number, it won't tell me if it's prime or not. I tried to put in woof, and that does indeed tell me that what I entered is invalid and that I need to enter another number.
int is_prime(int n)
for(b = 2; b<=sqrt(n); b++)
int a, ret, c;
ret = scanf("%d", &a);
if(ret == EOF)
if(ret == 1)
printf("Invalid input, please try again: \n");
while((c = getchar()) != '\n' && c != EOF)
int a, ret;
printf("Enter a number to test (negative number to stop): \n");
ret = read_an_int();
printf("End of file.");
if(is_prime(a) == 1)
printf("%d is prime\n", a);
printf("%d is not prime\n", a);
In other words, it scans in my function called read_an_int, but for some reason it doesn't read in the part where I have to say if it's a prime number or not.
like if(ret==a) and so on. Anyone know how I can fix it?