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 |
eric chen 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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.02153 seconds