Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » Console bug when used for input with C
Console bug when used for input with C [message #156540] Thu, 20 October 2005 15:51 Go to next message
Eclipse UserFriend
Originally posted by: nicholas_panagos.hotmail.com

Hello everybody,

The eclipse console has weird behaviour when used for input with C
programs.
I teach C to first year undergraduates and I want them to learn their way
through eclipse. But the small silly programs that ask you to input
characters have weird behaviour, if you use the eclipse console. It seems
like it groups all input and output commands and executes them
together...for example...
the following program:

#include <stdio.h>

int main() {

int n = 0;
printf("Gimme a number: ");
scanf ("%d", &n);
printf("\nThe number you entered was %d\n", n);

return 0;
}

has the following output:

4
Gimme a number:
The number you entered was 4


instead of

Gimme a number: 4
The number you entered was 4


is this a bug, or there's a setting to correct it?
I don't have such a problem when using C++ or Java.
Any suggestions?

Thanks!
Nikos
Re: Console bug when used for input with C [message #156584 is a reply to message #156540] Fri, 21 October 2005 04:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: screetch.gmail.com

Nikos Panagos wrote:
> Hello everybody,
>
> The eclipse console has weird behaviour when used for input with C
> programs.
> I teach C to first year undergraduates and I want them to learn their
> way through eclipse. But the small silly programs that ask you to input
> characters have weird behaviour, if you use the eclipse console. It
> seems like it groups all input and output commands and executes them
> together...for example...
> the following program:
>
> #include <stdio.h>
>
> int main() {
>
> int n = 0;
> printf("Gimme a number: ");
> scanf ("%d", &n);
> printf("\nThe number you entered was %d\n", n);
>
> return 0;
> }
>
> has the following output:
>
> 4
> Gimme a number: The number you entered was 4
Pretty normal output on any console you'll find, not just with eclipse's one

>
>
> instead of
>
> Gimme a number: 4
> The number you entered was 4
To obtain this output, you have to flush stdout before scanf'ing the
number. The output is flushed either implicitely when a newline
character is echoed on the console (printf("\n")) or explicitely with
fflush(stdout);

to get the output you wanted use this program :

#include <stdio.h>

int main() {

int n = 0;
printf("Gimme a number: ");
fflush(stdout);
scanf ("%d", &n);
printf("\nThe number you entered was %d\n", n);

return 0;
}

a very good example program to teach students about buffered streams :)
Re: Console bug when used for input with C [message #156609 is a reply to message #156584] Fri, 21 October 2005 14:33 Go to previous message
Eclipse UserFriend
Originally posted by: nicholas_panagos.hotmail.com

thanks for your answer...
Needless to say that I feel stupid! I was kinda hoping to be able
to get the same behaviour that i get when i run the program from
the command prompt from within the IDE without the need of flushing.
Thanks again!
Previous Topic:Problem in including files in makefile
Next Topic:import Visual Studio v/.1 project
Goto Forum:
  


Current Time: Sun Jul 20 14:50:57 EDT 2025

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

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

Back to the top