Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to clear stdin buffer in C

1 Answer

0 votes
#include <stdio.h>

int main(void)
{
    char ch;
    
    do 
    {
        printf("your code is here\n");
        printf("Enter a character (Q/q to quit): ");
        fseek(stdin, 0, SEEK_END);
        ch = getc(stdin);
    } while (ch != 'Q' && ch != 'q');
        
   return 0;
}

/*
 
run:

your code is here
Enter a character (Q/q to quit): a
your code is here
Enter a character (Q/q to quit): b
your code is here
Enter a character (Q/q to quit): ooo
your code is here
Enter a character (Q/q to quit): w
your code is here
Enter a character (Q/q to quit): q

*/





answered Sep 14, 2014 by avibootz

Related questions

2 answers 97 views
97 views asked Feb 9, 2021 by avibootz
1 answer 95 views
1 answer 90 views
1 answer 137 views
137 views asked May 27, 2015 by avibootz
...