>You are scanf'ing a char into an int. I am not sure that will work.
Why not? An int can hold all of the values that a char can and since they are both integral types, scanf and printf don't distinguish between the two as long as the values don't go out of bounds:
Code:
#include <stdio.h>
int main ( void )
{
int i = 0;
char c = 0;
scanf ( "%c %d", &i, &c );
printf ( "%d %c\n", i, c );
return 0;
}
Though most code checkers will warn you about different arguments for the corresponding format flag. Generally, while int and char are interchangeable in scanf it's best to either not do so or cast the result to avoid unforseen bugs:
scanf("%c",(char *)&letter);
All in all it's easier to avoid scanf altogether, this is my recommendation.
To solve your problem, there's a little trick called initialization. This is one of those times where leaving garbage values in your variables causes problems, initialize letter to any value and the program should work properly. I used
int letter = 0;
-Prelude