3 Answers
3

First of all, I agree with nonsensical: fflush(stdin) is a bad thing to do. Here's further explanation. (And if 9 experienced programmers all told me that I was doing something wrong, I'd believe them.)

Now, to try and help you debug your code, can you tell us whether this simplified code exhibits the same problem on your system?

but tell how to fflush the input buffer or clear it??
–
M_ESep 16 '12 at 10:29

stdin is buffered by design. Maybe you can read (fgets) and simply ignore any chars you don't want? Here's some further discussion and a method (though I recommend it only with reservations). Good luck!
–
ron.rothmanSep 16 '12 at 17:08

True--good point; but not an answer to OP's question. (And was already pointed out in PaulR's comment above.)
–
ron.rothmanSep 13 '12 at 22:59

No I think this is an answer. The OP thinks that getchar is being executed first because there is no output, then it waits on a key, then the program exits and stdout is flushed. It looks like printf is happening after because there was no newline in the printf and stdout was not explicitly flushed.
–
paddySep 13 '12 at 23:02

Except... in his comment above (response to WilliamPursell 19 mins ago) he says quite clearly that he tried that and didn't work. Right?
–
ron.rothmanSep 13 '12 at 23:04

I question if he actually tried flushing stdout and it didn't work. I suspect language issues. In any case, flushing stdin is clearly an error.
–
Carey GregorySep 13 '12 at 23:43

I am flushing stdin because I need it in future. This is sample of a program, but after this works I will add some code that read data from console. So, I wrote fflush(stdin) . So, The error doesn't happen because of this line :( You are wrong @nonsensical. And I tried the code without it and the same algorithm happen that I read from console before output the string.
–
M_ESep 14 '12 at 8:34