I am having trouble restricting the character lengths in this data entry form I am making using do/while with nested if statements. I have tried to alter these with strlen functions but i can't get it to constain the character length of the array. Basically, I want the person to be only able to input alpha numeric characters for the name of the dog's species with up to 22 characters only.
Code:
int main(void)
{
/*variables*/
int errors;
int i;
char dog_s[22] = {'\0'};
do
{
errors = 0;
printf("Enter The breed, species of the dog");
printf(" , No more than twenty two characters\n");
scanf("%22s", dog_s);
fflush(stdin);
if (strlen(dog_s) < 0 || strlen(dog_s) > 22)
errors=1;
}
while (errors > 0);
for (i = 0 ; i <= (int)strlen(dog_s) ; ++i)
{
if (isdigit(dog_s[i]) == 0)
errors=0;
}
return 0;
}