Problem with C in Eclipse 3.3 [message #197957] |
Sun, 22 July 2007 19:20 |
Eclipse User |
|
|
|
Originally posted by: omniparagon.hotmail.com
I know this is basic stuff but i really don't know how to solve it.
Look at this code:
#include <stdio.h>
int main()
{
int number;
printf( "Please enter a number: " );
scanf( "%d", &number );
printf( "You entered %d", number );
return 0;
}
If i run it like an executable it does what's expected:
Please enter a number: 2
You entered 2
The problem is, if i run it in eclipse's console, "Please enter a
number: " doesn't appear. the program just waits for my input like it
has ignored the printf. The i put 2, for example and what appears is:
2
Please enter a number: You entered 2
What i want is the console to do the same as the executable. Can it be done?
Thanks
|
|
|
Re: Problem with C in Eclipse 3.3 [message #197965 is a reply to message #197957] |
Sun, 22 July 2007 19:40 |
Eclipse User |
|
|
|
Originally posted by: dmsubs.NOSPAM.consertum.com
This is because the output is only 'flushed' on a newline. You need to flush()
the output, or put a newline at the end of the string.
--
Derek
Pombal wrote:
> I know this is basic stuff but i really don't know how to solve it.
> Look at this code:
>
> #include <stdio.h>
>
> int main()
> {
> int number;
>
> printf( "Please enter a number: " );
> scanf( "%d", &number );
> printf( "You entered %d", number );
> return 0;
> }
>
>
> If i run it like an executable it does what's expected:
> Please enter a number: 2
> You entered 2
>
> The problem is, if i run it in eclipse's console, "Please enter a
> number: " doesn't appear. the program just waits for my input like it
> has ignored the printf. The i put 2, for example and what appears is:
> 2
> Please enter a number: You entered 2
>
> What i want is the console to do the same as the executable. Can it be
> done?
> Thanks
|
|
|
Re: Problem with C in Eclipse 3.3 [message #197973 is a reply to message #197965] |
Sun, 22 July 2007 20:30 |
Eclipse User |
|
|
|
Originally posted by: omniparagon.hotmail.com
Derek Morris escreveu:
> This is because the output is only 'flushed' on a newline. You need to
> flush() the output, or put a newline at the end of the string.
>
Sorry but i don't know how to use flush() and inserting a newline at the
end of the string didn't work... :S Any suggestions?
thanks
|
|
|
Re: Problem with C in Eclipse 3.3 [message #198160 is a reply to message #197973] |
Tue, 24 July 2007 18:47 |
Eclipse User |
|
|
|
Originally posted by: my.exmpl.com
Pombal skrev:
> Derek Morris escreveu:
>> This is because the output is only 'flushed' on a newline. You need to
>> flush() the output, or put a newline at the end of the string.
>>
> Sorry but i don't know how to use flush() and inserting a newline at the
> end of the string didn't work... :S Any suggestions?
> thanks
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int number;
printf( "Please enter a number: " );
fflush(stdout);
scanf( "%d", &number );
printf( "\nYou entered %d", number );
fflush(stdout);
return EXIT_SUCCESS;
}
you should read up some tutorials on c... try search google :P
|
|
|
Powered by
FUDForum. Page generated in 0.03953 seconds