Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » can anyone good with eclipse look at my console error? There was no error before and no error in com(I don't want use fflush each time)
can anyone good with eclipse look at my console error? There was no error before and no error in com [message #1784671] Sun, 01 April 2018 21:39 Go to next message
eric chen is currently offline eric chenFriend
Messages: 1
Registered: April 2018
Junior Member
favorite
This question may already have an answer here:

printf not printing on console 7 answers
So I have windows 10, MinGW64 installed with Eclipse C/C++ Development tool. Right now I have no idea why my eclipse console is not displaying right. The problem kind goes away if I use fflush after printf. But in my old eclipse I never had this problem.

In my windows command prompt everything works fine:

C:\Users\Jwill\Documents>gcc -o cal.exe cal.c

C:\Users\Jwill\Documents>cal
Enter an operator (+, -, *,): +
Enter two operands: 2 4
2.0 + 4.0 = 6.0
This is my code:

#include<stdio.h>

int main() {

char operator;
double firstNumber,secondNumber;

printf("Enter an operator (+, -, *,): ");
//fflush(stdout);

scanf("%c", &operator);

printf("Enter two operands: ");
//fflush(stdout);
scanf("%lf %lf",&firstNumber, &secondNumber);
switch(operator)
{
case '+':
printf("%.1lf + %.1lf = %.1lf",firstNumber, secondNumber, firstNumber + secondNumber);
break;

case '-':
printf("%.1lf - %.1lf = %.1lf",firstNumber, secondNumber, firstNumber - secondNumber);
break;

case '*':
printf("%.1lf * %.1lf = %.1lf",firstNumber, secondNumber, firstNumber * secondNumber);
break;

case '/':
printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber / secondNumber);
break;

// operator doesn't match any case constant (+, -, *, /)
default:
printf("Error! operator is not correct");
}

return 0;
}
When I compiles and run this C code in my eclipse, everything shows up blank in my console. Then I typed + and 2 and 2 and it compiles but not displaying right.

+
2
2
Enter an operator (+, -, *,): Enter two operands: 2.0 + 2.0 = 4.0
This problem will appear in every C code if I don't comment out fflush. In my old eclipse I never had this problem and didn't have to use fflush.
Re: can anyone good with eclipse look at my console error? There was no error before and no error in [message #1784738 is a reply to message #1784671] Tue, 03 April 2018 11:37 Go to previous message
Ilya Basin is currently offline Ilya BasinFriend
Messages: 25
Registered: October 2011
Junior Member
Although your description is confusing, I can confirm that when "Allocate console" checkbox is cleared, Eclipse does not show the program's output.

You should check the checkbox in your launch configuration and also you should either use newlines in your printf calls or call fflush.
Previous Topic:Why can't a test suite be split into multiple OS processes?
Next Topic:How to setup arm-linux-gnuabihf cross-compile ?
Goto Forum:
  


Current Time: Thu Sep 26 07:02:38 GMT 2024

Powered by FUDForum. Page generated in 0.03101 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top