My question is when does this function works improperly and why?
Technically it works improperly when you call it with an input stream or an update stream in input mode. That is, if you use fopen() with a "w" mode, or a "+" mode and you're currently in the process of reading from the stream, or stdin.
In practice, all of the above situations are okie dokie iff the compiler supports them (and some do, including Borland and Microsoft compilers). In terms of best practice, fflush() on an input stream is frowned upon.
However, note that calling fflush() on an output stream is both well defined and recommended for things such as forcing a user prompt to display, well...promptly. :)
Nowadays I use scanf("[^\n]") to flush input stream. Is this ok?
Close. The correct call for scanf() to read up to a newline would be:
scanf("%*[^\n]");
This isn't complete though, because the newline will still be in the stream. You still need to extract it. One way would be to add an ignored character match in the format string:
scanf("%*[^\n]%*c");
This might not be as flexible though, if you want to do other stuff like count discarded characters. Another way would be to call getchar() after scanf():
scanf("%*[^\n]");
getchar();
Finally, there's the far more common (and faster!) method of calling getchar() in a loop. I'll even give you a function that you can call instead of having to write it …