Reputation: 1
#include <stdio.h>
int main()
{
char gh, hj;
printf("Enter the first letter of your name \n");
gh=getchar();
printf("Enter the last letter of your name\n");
hj=getchar();
getchar();
printf("The first and last leter of your name is %c%c", gh, hj);
return 0;
}
When I run this code the second %c
doesn't get printed, unlike the first one. Why is this happening?
Upvotes: 0
Views: 52
Reputation: 125
Since the second getchar
peruses the newline character after the character you entered.
Upvotes: 1