0

I have eclipse C/C++ installed along with MinGW64 on my windows 10. The weird things when I run my code on command prompt, everything looks perfect in the console, when it comes to printf() or scanf().

etting.

1 Answers1

-1

There's nothing too strange. Usually, the standard output is line buffered (when connected to a terminal). So, unless you have used a newline (or, flush manually), the output would be in the buffer, it will not be flushed to terminal.

If you don't want to use fflush(), you can force flashing by including a newline in your print statement, like

printf("Enter number of rows: \n");

As found in this forum, for MinGW,

added a PATH variable set to C:\MinGW\bin in the Run Configuration

can be tried also.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
  • hey sir but in my old eclipse I never had this problem, and I don't need fflush to have the right console in windows command prompt. Is there anyway I cannot use fflush. Can you please write an answer? –  Mar 30 '18 at 02:50
  • @DaChen I'd like to help you for sure, but preferably not over email, that way the information is not properly shared. You can always edit your question to add additional information, if it is related. – Sourav Ghosh Mar 30 '18 at 03:00
  • Sir I edit my answer. I still think something is wrong with my eclipse figuration –  Mar 30 '18 at 03:03
  • @DaChen did you try [this](https://www.eclipse.org/forums/index.php/t/156519/)? – Sourav Ghosh Mar 30 '18 at 03:08
  • thank you sir I will try to that forum thing, but I already set the C path. Or the code won't compile on command prompt or eclipse –  Mar 30 '18 at 03:14
  • sir can you show me how to do the run configuration path? –  Mar 30 '18 at 03:15
  • sir I tried everything, linker flag thing. I'm not sure what's the problem. Guess I'll have to stuck with fflush? –  Mar 30 '18 at 03:18
  • Sir can you show me how to do run configuration value? –  Mar 30 '18 at 03:21
  • Re “So, unless you have used a newline (or, flush manually), the output would be in the buffer, it will not be flushed to terminal”: That is not true in standard C. Performing a `scanf` should flush output. C 2011 [N1570] 7.21.3 says “Furthermore, characters are intended to be transmitted as a block to the host environment when a buffer is filled, when input is requested on an unbuffered stream, or when input is requested on a line buffered stream that requires the transmission of characters from the host environment.” The problem is Eclipse is not conforming to the standard. – Eric Postpischil Mar 30 '18 at 09:49
  • "If you don't want to use fflush(), you can force flashing by including a newline " --> Not quite so. [What are the rules of automatic flushing stdout buffer in C?](https://stackoverflow.com/q/39536212/2410359) – chux - Reinstate Monica Mar 30 '18 at 15:55
  • I tried that, it didn't work. –  Mar 30 '18 at 21:45