Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Problem with C in Eclipse 3.3
Problem with C in Eclipse 3.3 [message #197957] Sun, 22 July 2007 19:20 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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
Previous Topic:Override a default content type?
Next Topic:multi-platform c++ development
Goto Forum:
  


Current Time: Fri Dec 27 01:32:23 GMT 2024

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

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

Back to the top