delayed console display [message #883967] |
Sat, 09 June 2012 16:16  |
Eclipse User |
|
|
|
I ran a tutorial (avg.c - pasted below) that accepts 2 numbers from the
keyboard, but the text from the puts function does NOT appear in the
Eclipse Console Window until after I have entered the 2 numbers.
avg.c runs fine from a DOS window.
The Eclipse Console Window first appears blank.
Then I type the following:
10<enter> the numbers appear in green as I type
20<enter> then the following appears:
Enter the 1st number:
Enter the 2nd number:
The average is 15.000000
Can someone explain to me what I am doing wrong or how I can correct
this issue?
I am using the C Project to build and not the C++ Project.
first.c (see last) was the first program from the tutorial that I
compiled which ran as expected and without issue (first.c does NOT use
keyboard input).
Any help will be appreciated.
Thanks, Tracey
/* avg.c: Averages 2 integers */
#include <stdio.h>
int main() {
int num1, num2;
float sum;
puts("Enter the 1st number:");
scanf("%d",&num1);
puts("Enter the 2nd number:");
scanf("%d",&num2);
sum = num1 + num2;
printf("The average is %f\n", sum/2);
return 0;
}
/* first.c: A First Program */
#include <stdio.h>
int main() {
puts("Hello World");
return 0;
}
|
|
|
Re: delayed console display [message #884018 is a reply to message #883967] |
Sat, 09 June 2012 19:00  |
Eclipse User |
|
|
|
hi,
yes, the text from puts() should appear before you have to enter a number.
So try a flush(), after puts(). flush() is emptying the output buffer.
I know this procedure when using printf() within a program.
The flush() statement is necessary after a printf(), if the output from printf() shall be visible immediately when the program executes the printf() statement. Otherwise the output occurs only when the output buffer is filled.
Normally puts() contains a flush() statement internally.
If flush() solves your problem then you should have a look on your OS configuration. I am not an expert but anywhere there should be a setting how output buffering occurs.
Perhaps your basic library included by stdio.h is not up to date.
|
|
|
Powered by
FUDForum. Page generated in 0.03205 seconds