I was writing a code to check occurrence of a char in a string.After running the compiler took input for the string but it skipped the 2nd scanf just below the for loop. But when i wrote the scanf to get character above the loop both scanf were running. So i tried fflush(stdin) because i just know i little bit about buffer. Can someone explain in detail how is the compiler working with and without fflush(stdin).
PS : I could have used gets() I just want to know the concept.
int i, k=0;
char a[20], ch;
for(i=0; i<5; i++);
scanf("%s", &a);
//fflush(stdin);
scanf("%c", &ch); //This line is not working if i dont put fflush(stdin) or write it above loop