Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Adding program(cannot insert the interger input )
Adding program [message #1742661] Tue, 06 September 2016 13:05 Go to next message
Massimo Mancini is currently offline Massimo ManciniFriend
Messages: 24
Registered: September 2016
Junior Member
Dear all,

first of all I would like to say that is my first time I am using eclipse and for that reason I've being donig some simple exercise to practice and to get familiar with the C compilator.

So, as the adding program here below it show a simple adding program that after being lunched it doesn't ask to insert the input data (integer 1 & 2).



#include <stdio.h>

int main ( void )

{
int integer1;
int integer2;
int sum;

printf("Enter first integer\n");
scanf("%d", &integer1);

printf("Enter second integer\n");
scanf("%d", &integer2);

sum = integer1 + integer2;

printf("Sum is %d\n", sum);

return 0;

} /* fine della funzione main */



Why that? Is there somenting wrong or it is an eclipse setting problem?
(I am using the Mars version).

Thanks for your kind advice,
Massimo
Re: Adding program [message #1742689 is a reply to message #1742661] Tue, 06 September 2016 16:09 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
It worked for me but I think the problem is that the output stream (stdout) is buffered. It depends on your operating system and the library being used.

Try this at the beginning of your main
setvbuf(stdout, NULL, _IOLBF, 0);
This says to only buffer until an end of line is sent. Then the buffer is emptied.
There are other options. For example, _IONBF means no buffering.

More info: http://www.cplusplus.com/reference/cstdio/setvbuf/

Note this won't change std::iostream. There are different calls for that.


[Updated on: Tue, 06 September 2016 16:11]

Report message to a moderator

Re: Adding program [message #1742692 is a reply to message #1742689] Tue, 06 September 2016 16:34 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
David:

The problem here was that the OP did not force the run configuration to allocate a console to the run. It is necessary for feeding input from the keyboard.

The output file buffering does not hurt here, as the prompts are finished with a newline.

---

Another thing is that the OP posted several nearly similar questions with slightly different headers. It lowers the probability of good responses.


--

Tauno Voipio
Re: Adding program [message #1742705 is a reply to message #1742692] Tue, 06 September 2016 17:10 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
I didn't see the other posts.
Not sure about the buffering.
I had to force line buffering for my system which has a rather large buffer otherwise.
What I posted is what I normally use.

[Updated on: Tue, 06 September 2016 17:37]

Report message to a moderator

Re: Adding program [message #1742711 is a reply to message #1742705] Tue, 06 September 2016 18:43 Go to previous message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
I tried it on OS X 10.9.5, and it was sufficient to set the console allocation check in run configuration.

From a terminal (under Eclipse or stand-alone) it did run without any changes.

I do not know anything on the behaviour under any of the current Windowses, however.

For the other posts: There's one more here in CDT group and another in Newcomers.

--

-TV


--

Tauno Voipio

[Updated on: Tue, 06 September 2016 19:38]

Report message to a moderator

Previous Topic:"Could not be resolved" | Errors
Next Topic:build beserk
Goto Forum:
  


Current Time: Sat Apr 20 04:30:07 GMT 2024

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

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

Back to the top