Please tell me why my else if
does not work?
I'm trying to check if the input value is correct or not.
If it is not isalpha()
or isdigit()
it will out put an error!
Everything works okay except the else if
!
Thank you!
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char name;
int len = 0;
printf("Enter the user name: ");
name = getchar();
while (name != '\n')
{
name = getchar();
int i;
for (i = 0; i <= (sizeof(name)/2); i ++)
{
len++;
}
}
printf("len = %d\n", len);
if((len < 5) || (len > 10 ))
{
printf("Output: input is invalid");
}
else if((isdigit(name)) || (isalpha(name))) //this one does not work
{
printf("invalid");
}
else
{
printf("Output: input is invalid");
return 0;
}
return (0);
}