Please give me a clear explanation for the below C program. It doesn't getting a character input after getting a string as an input .
This doesn't works
#include<stdio.h>
int main(){
char name[25],alpha;
printf("Enter your name \n");
scanf("%s",name);
printf("\nEnter a character \n");
scanf("%c",&alpha);
printf("\nyour name is %s, and you entered %c",name,alpha);
return 0;
}
This works
#include<stdio.h>
int main(){
char name[25],alpha;
printf("\nEnter a character \n");
scanf("%c",&alpha);
printf("Enter your name \n");
scanf("%s",name);
printf("\nyour name is %s, and you entered %c",name,alpha);
return 0;
}
why? what's the reason behind this execution. Thanks in advance