So I'm new to coding in C and coding in general. I'm learning with a book and a code in there just won't work and I don't know why. It's probably a trivial matter but as I said..I'm a bloody noob. Anyway this is the code:
#include <stdio.h>
void main()
{
char a, b;
printf("Welches Zeichen ist groesser?");
printf("\nGeben Sie ein Zeichen ein:");
a = getchar();
printf("Nun ein anderes Zeichen:");
fflush(stdin);
b = getchar();
if( a > b)
{
printf("'%c' ist groesser als '%c'!\n", a, b);
}
else if( b > a)
{
printf("\n'%c' ist groesser als '%c'!\n", b, a);
}
else
{
printf("\nBitte nicht zweimal das gleiche Zeichen eingeben!");
}
}
I don't get any compiler error messages, it just seems to 'skip' the second getchar and go straight to the last printf. I feel like it has something to do with fflush(stdin). It doesn't matter if it's in the code or not. I already tried fflush(stdout) but with the same outcome. Can somebody tell me why and please don't be too harsh. Thanks in advance!