i have a problem with scanf and input buffer in my program.
first i ask the user for input :
char someVariable;
printf("Enter text: ");
scanf(" %c",&someVariable);
and then i have a loop that goes over the input one char at a time in scanf until it reaches \n. the problem is that after the loop is done, somehow, there is still something in the buffer so this function (which is being called in a loop) gets called again and ruins the logic in my program.
how can i force clear the input buffer?
i can only use scanf (assignment requirements)
void checkType(){
char userInput;
char tempCheckInput;
printf("Enter Text: ");
scanf(" %c",&userInput);
while (userInput != '\n'){
tempCheckInput = userInput;
scanf("%c",&userInput);
ignore the end of the loop, that's the part i get the input