This is because you type a letter and then press the enter key. Use another getchar() to eat the trailing newline.
So change this:
k = toupper(getchar());
:
k = toupper(getchar()); getchar();
When the user enters something, he goes into the stdin stream (standard input), and the system guarantees that what the user entered in the internal buffer is saved. So here is what happened to your code:

So the solution is the final new line !
Easter Egg Tips:
You should get the following:
warning: implicit declaration of function 'printf'
because you are missing the IO header, so you should add at the beginning of your main file:
#include <stdio.h>
Similarly, you should add:
#include <ctype.h> // for toupper() #include <stdlib.h> // for exit()
Another solution would be to use fgets () , see this question for more C - scanf () vs gets () vs fgets () .
I had a similar problem with your scanf() , and I was in your place, so I wrote down the solution for a while.
source share