below two are same program except i interchange to accept input value ....in the first program i accept first using scanf and the by getchar()...which didnt allow to accept character value . but in the second program i first accept getchar()value and then scanf(). so it works fine but i dont understand why frist value doesnt work. so please help me out
#include<stdio.h>
#include<string.h>
int main()
{
char ch;
char name[20];
printf("enter your name\n");
scanf("%s",&name);
printf("enter single value\n");
ch=getchar();
}
output
enter your name
lobsang
enter single value //not allowing to enter the value here
lobsiphone:cprogram gyurmey$
........................................................................................................
#include<stdio.h>
#include<string.h>
int main()
{
char ch;
char name[20];
// printf("enter your name\n");
// scanf("%s",&name);
printf("enter single value\n");
ch=getchar();
printf("enter your name\n");
scanf("%s",&name);
}
output
enter single value
a
enter your name
lobsang
lobsiphone:cprogram gyurmey$