I have this code, a program to take an integer from a user that's negative, if not trap them in a loop until they enter a negative integer. I have this part down, however, how could i clear the input buffer?
I tried to use while ((getchar()) != ‘\n’); after the first scanf_s but it fails.
here is code
#include <stdio.h>
int main()
{
int num;
printf("Please enter a negative integer");
scanf_s("%d", &num);
while (num >= 0.0)
{
printf("Please enter a negative integer!\n");
scanf_s("%d", &num);
}
printf("%d", num);
system("pause.exe");
return 0;
}