NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

problem with output Window

 
Post new topic   Reply to topic    NetBeans Forums -> C/C++ Users
View previous topic :: View next topic  
Author Message
filippo.sandri
Posted via mailing list.





PostPosted: Mon Feb 28, 2011 9:32 pm    Post subject: problem with output Window Reply with quote

If my source file code contains the function "scanf(something)" and i'm
using the Output Window as Console Type, the generated file .exe do not
run correctly.
For example, if this is my code:


#include <stdio.h>
#include <stdlib.h>

int main() {
int first = 0;
int second = 0;
int third = 0;
printf("\n insert the first number ");
scanf("%d", &first);
printf("\n insert the second number ");
scanf("%d", &second);
third = first * second;
printf("\n the result of multiplication is: %d \n\n ", third);
return(0);
}

after compilation, the DEFAULT CONSOLE will return:

"insert the first number" (here insert 8 and press enter)
"insert the second number" (here insert 7 and press enter)
"the result of multiplication is 56
Press [Enter to close the terminal..."

but if choose as output the OUTPUT WINDOW of Netbeans it happens that,
when I launch the application, at first I cannot read anything and only
after inserting consecutively "8, [enter],7, [enter]" the OUTPUT WINDOW
shows:

"8
7
insert the first number
insert the second number
the result of multiplication is: 56
RUN SUCCESSFUL (total time: 8s)"

If C code don't contain "scanf" function, the OUTPUT WINDOW too run
correctly!
Why? Somebody knows this problem?


Filippo Sandri address-removed
Back to top
knightahmed



Joined: 12 Nov 2011
Posts: 1
Location: Russia

PostPosted: Sat Nov 12, 2011 2:49 pm    Post subject: Reply with quote

I have the same problem with printf in netbeans........does any body have a solution for this.........

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int a,b,c;

printf("Enter A: \n");
scanf ("%d",&a);
printf("Enter B: \n");
scanf ("%d",&b);
c = a+b;
printf("The addition is %d",c);

return 0;

}
Back to top
Ivan Soleimanipour
Posted via mailing list.





PostPosted: Mon Nov 28, 2011 10:23 pm    Post subject: problem with output Window Reply with quote

On 11/12/11 06:49, knightahmed wrote:
Quote:
I have the same problem with printf in netbeans........does any body have a solution for this.........

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int a,b,c;

printf("Enter A: \n");
scanf ("%d",&a);
printf("Enter B: \n");
scanf ("%d",&b);
c = a+b;
printf("The addition is %d",c);
^
shouldn't there be a \n here?

when you use printf the output is buffered.
If you're outputting to a terminal the buffer gets flushed only on newlines.
In your case the program exited w/o the last printf's output getting flushed.

You can also force the flushing of the buffer using something like this:

printf("Enter A: ");
fflush(stdout);

Note how there's no "\n" here. This idiom will allow you to be
able to type the input to your prompt on the same line.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> C/C++ Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo