Thor
Thor

Reputation: 10048

Eclipse IDE always ask for input first regardless of actual code order

I'm currently studying beginner C programming using Eclipse IDE.

Below is a very basic program that suppose to print out a line first, take in some input, and then print out a second line. But my Eclipse always ask me for the input first before printing out the two lines together afterwards.

This is extremely frustrating because it is something so simple and doesn't work. What am I doing wrong?

#include <stdio.h>

int main(void){

    int aNumber;

    printf("first line\n");
    scanf("%d", &aNumber);
    printf("second line with %d", aNumber);

    return 0;
}

enter image description here

Upvotes: 1

Views: 328

Answers (1)

maycon kruger
maycon kruger

Reputation: 49

Had the same problem once. Solved it by flushing stdout.

#include <stdio.h>

int main(void){
  int aNumber;
  printf("first line\n"); 
  fflush(stdout); // Prints stdout content

  scanf("%d", &aNumber);
  printf("second line with %d", aNumber);

  return 0;
}

Upvotes: 1

Related Questions