I have the following program:
int main(int argc, char *argv[])
{
char ch1, ch2;
printf(\"Input the first character:\"); // Line 1
scanf(\"%c\", &ch
Short, portable and declared in stdio.h
stdin = freopen(NULL,"r",stdin);
Doesn't get hung in an infinite loop when there is nothing on stdin to flush like the following well know line:
while ((c = getchar()) != '\n' && c != EOF) { }
A little expensive so don't use it in a program that needs to repeatedly clear the buffer.
Stole from a coworker :)