I am a java programmer and started learning C recently. I was going through headfirst C and wrote one of the example programs in Eclipse (with CDT). Here is the program
#include <stdlib.h>
#include <stdio.h>
int main()
{
char card_name[3];
puts("Enter the card_name: ");
scanf("%2s",card_name);
int val = 0;
if(card_name[0] == 'K'){
val = 10;
}else if (card_name[0] == 'Q'){
val = 10;
}else if(card_name[0] == 'J'){
val = 10;
}else if(card_name[0] == 'A'){
val = 11;
}else{
val = atoi(card_name);
}
printf("The card value is: %i\n",val);
return 0;
}
When I run it on eclipse, the line containing puts should be executed and then the user should enter in eclipse console and then the scanf line should execute.
But it doesn't happen that way, when I run it, it just expects the user to enter first on the eclipse console, then execute the puts line and finally the scanf line. I couldn't understand this behavior. Can someone help me on this ?