bunnyannihilator89
bunnyannihilator89

Reputation: 115

Netbeans - C - Why does input runs before the print command?

My code in netbeans is as follows:

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

    int a = 2;
    int b;
    printf("b = ");
    scanf("%d", &b);
    printf("\n%d",a+b);
    return (EXIT_SUCCESS);
}

The problem is when I run this, the first thing it waits for is the user input, it doesn't show "b = ". As soon as I input something it shows everything.

This is a problem because the user must see the text to know what he needs to input (word or number). How do I fix this?

Note: I'm using MinGW (and MSYS for make).

Upvotes: 2

Views: 235

Answers (1)

Jason
Jason

Reputation: 32520

printf is buffered on stdout ... therefore you won't see the output until there is either an end-of-line placed in the buffer, the buffer is filled to its max capacity, or the buffer is explicitly flushed using fflush.

Upvotes: 3

Related Questions