2

I have installed MinGW on netbeans for C and C++ programming.
Here is a simple code that I am trying to run on netbeans :

#include <stdio.h>
int main(int argc, char** argv) {
    printf("Inside Main...\n");
    int n;
    printf("Enter : ");
    scanf("%d", &n);  // When I remove this line, it is working.
    printf("You have entered %d.", n);
    return (1);
}

Whenever I try to access any value from netbeans console, I don't see anything.

Output with scanf(...)

enter image description here

Output without scanf(...)

enter image description here

And if I try to run these code from cmd, all are working

11
  • 1
    I am not sure try adding \n after printf"Enter..\n");
    – Gopi
    Dec 18, 2014 at 18:36
  • 1
    I'm not sure too, but you could try fflush(stdout));. Dec 18, 2014 at 18:37
  • possible duplicate of Programs with the scanf not working properly in NetBeans
    – Rizier123
    Dec 18, 2014 at 18:38
  • Try to return 0 at the end. Otherwise go to project properties then to run at the bottom and change the console type from internal terminal to external terminal
    – Rizier123
    Dec 18, 2014 at 18:39
  • @Gopi adding \n is not working.
    – afzalex
    Dec 18, 2014 at 18:41

2 Answers 2

2

for scanf() you must use Netbeans External Terminal !

enter image description here

Normal Run

enter image description here

You can also use Netbeans Standard Output !
But this is more misleading.
While you see an empty Terminal do input 123

enter image description here

after hit enter , you get the output all at once .

enter image description here

1

I had the same issue while running a CPP program.External output didn't helped me. I set the console type to Standard output and it solved the issue.

Right Click cpp Application-->properties-->run--->Consoletype to standard output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.