Mesbahul Hasan Rafi
Mesbahul Hasan Rafi

Reputation: 1

Don't getchar function print the second input?

#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

Answers (1)

MIH
MIH

Reputation: 125

Since the second getchar peruses the newline character after the character you entered.

Upvotes: 1

Related Questions