Use of Printf and Scanf in Eclipse and Netbeans - C Language

Asked

Viewed 353 times

0

Good night. I have the program below that asks the user to enter 2 numbers and then present them. Code Blocks is working correctly, but when running in Eclipse or Netbeans, the system is waiting for the numbers to be entered without the messages being shown on the printf. Does anyone know how to solve?

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

int main(int argc, char** argv) {

int num1, num2;

printf ("Digite o primeiro numero: ");

scanf("%d", &num1);

printf ("Digite o segundo numero: ");

scanf("%d", &num2);

printf ("Os números diigitados foram %d e %d.", num1, num2);

return 0;

}

Console result:

5
5
Digite o primeiro numero: Digite o segundo numero: Os números digitados        
foram 5 e 5.
  • I ran your program and nothing went wrong, see.

  • Yes, in Code Blocks it works normally but in Eclipse and Netbeans it doesn’t. It must be some problem with IDE configuration.

  • What seems to have happened is that in these Ides he is following the standard bufferization of stdout: print when having a \n or reach the end of the program. If you break lines (or change the bufferization to byte to byte) you should get a better result. There are two ways to test this: (a) by putting \n in each printf or (b) keeping the prints the way they are, only going to stderr

  • @Even though the n remains with the same problem, the console only displays the messages in the printf after typing the numbers. I couldn’t use stderr, you can show me?

  • fprintf(stderr, "o resto normalmente como printf");

  • I typed this way but showed no error. The problem continued.

Show 1 more comment

1 answer

-2

if it is in the NETBEANS Do the execution by the external terminal, click on the project (inside netbeans) right-click properties(properties) -> look for the Run(Run) option> first column in the right-hand Console type option switch to External terminal.

Click Apply Down There and An Ok.

Ready run will appear the DOS screen and you will be able to run normal.

video showing the step by step: https://www.youtube.com/watch?v=IelB0dRmr84&list=LL&index=7

Browser other questions tagged

You are not signed in. Login or sign up in order to post.