Hi,

I just took up c programming and like it so far. Now I got a problem reading in a character in a program. The program looks like this:


insert
Code:
#include <stdio.h>

main()
{
    char c1, c2;
    printf("Letter 1: ");
    c1 = getchar();
    
    printf("Letter 2: \n");
    c2 = getchar();
    
    printf("c1 %c, c2 %c", c1, c2);
    if (c1 < c2)
        printf("Letter 1 is before Letter 2.\n");
    else
        printf("Letter 1 is after Letter 2\n");
}
The program reads in c1, but ignores c2. Anyone knows why?
I have the same problem using scanf (see below).


insert
Code:
#include <stdio.h>

main()
{
    char c1, c2;
    
    printf("Letter 1: ");
    scanf("%c", &c1);
    
    printf("Letter 2: ");
    scanf("%c", &c2);
    
    printf("\nc1 %c, c2 %c", c1, c2);
    if (c1 < c2)
        printf("\nLetter 1 is before Letter 2.\n");
    else
        printf("\nLetter 1 is after Letter 2\n");
}
Any help is appreciated. Thank you.