I have function, which should count how many characters have the longest word, but it counts wrong.
For example, if I enter two words when first one is shorter than second one: "my name" program shows me that the longest word has 2 chars. But when i enter "name my" it shows that the result is 4. why is that ?
void max_chars(ListNodePtr sPtr)
{
int i = 0;
int max = 0;
while (sPtr->next != NULL) {
if (isalpha(sPtr->data)) {
i++;
} else {
if (i > max) {
max = i;
}
i = 0;
}
sPtr = sPtr->next;
}
printf(" \n The Longest word have : %d chars \n", max);
}