Hi!
I'm trying to validate the input as 'A' or 'P' with the following function:
char Get_l(void)
{
//declare local variables
char v_let, clearkbd;
printf("Enter A(for AM) or P(for PM):");
v_let = getchar();
while((clearkbd = getc(stdin))!= EOF && clearkbd != '\n');
//Loop until the user enters either A or P
while(v_let != 'A' && v_let != 'P')
{
printf("The letter you entered is not valid. Please enter \
A(for AM) or P(for PM):");
v_let = getchar();
while((clearkbd = getc(stdin))!= EOF && clearkbd != '\n');
}//end of while
return v_let;
}//End of Get_l
If I test it without any previous data entered, it works great. If there was data entered before, and I type A, I get "invalid" message. Can you help me find the problem?