Excuse me if this might be painfully obvious, but I've not found an answer to this so far. I just started learning some C basics after mostly working with Java so far.
I've tried to follow this tutorial and am currently very confused with how printf and scanf behave in the Eclipse console.
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char character;
printf("Enter a character: ");
scanf("%c", &character);
printf("Character: %c",character);
return 0;
}
What I'm expecting to happen, based on the linked tutorial:
Enter a character: _
I'm expecting this line to be printed to the console and then wait for my input where I put _
as a placeholder, before then printing Character: _
. This behaviour is how I'd expect it in Java.
What actually happens:
On running my code, the console stays completely empty. At first I spent 2 hours thinking the program was simply not executing. Luckily I then noticed that the empty console was simply my prompt to give my user input. Once I input a character and press enter, the printf's are written into the console like so:
a
Enter a character:
Character: a
Is this behaviour normal and my expectations for the behaviour are just plain wrong? If so, how would I go about realizing my desired behaviour of first being presented with the prompt to input a character?