I'm new to the C language and have to write a program that asks the user to type the letter "t" in uppercase or lowercase and then press enter. The program should inform you if you entered the letter "t" or other data. The case of a user's input like "tre" should be treated as invalid. I've tried something like this:
#include <stdio.h>
int main(void) {
char input;
printf("Please type letter \"t\" in upper or lower case:\n");
input = getchar();
printf("%c", input);
if (input != 't')
{
printf("\nWrong input");
return 0;
}
else {
printf("\nYou have entered: \"%c\"", input);
}
}
The issue is that if the user's input is something like "tasd" or "tre" or anything that starts with the letter "t", only the first letter is read and the if statement is treated as true. I've tried to research the answer but I couldn't find anything useful.