I want to get the number of letters of the longest word. If I input something like "hello me" I get 5 but if I write something longer like "league of legends" I get 6 instead of 7. Why?
#include <stdio.h>
int longest_word(const char string[]){
int i;
int max;
int cont;
i=0;
while(string[i]!='\0'){
for(cont=0;string[i]!=' '&& string[i]!='\0';i++)
cont++;
if (cont>max)
max=cont;
++i;
}
return max;
}
int main(void){
char f[100]; #maybe this is the problem?
int i;
printf("input a string: ");
scanf("%s",f);
i=longest_word(f);
printf("%d",i);
return 0;
}