I came across this problem during a personal project, it is even more curious, I wanted to please ask anyone who can give me a light with this, since I have solved the problem in other languages only in C that have not yet. p>
How can I do to detect the largest word in a string, in the case of a phrase typed by the user? I'm having difficulty right in the part when I detect the first whitespace, inside the 'If' inside the 'for' loop.
for(i = 0; str[i] < MAX; i++){
if(str[i] == ' '){ //CONTINUAR a string depois do primeiro espaço;
strcpy(maior, str); //Copia palavra em maior
strcpy(temp, str);
}
- Right here, I can not continue, I do not know how to keep comparing, and he always gives me the last word of the sentence, never the greater. I have tried to set up my own functions when I detect the first space, it validates the string up to that point and copies it to another char string, but it did not work.
If someone has a solution, I could only solve this with the function in JAVA that calls Split that fragments the string into a vector with each index being a word, it is easier to compare. I can not imagine if something similar can be done in C. More to heal this curiosity of mine that I come here. Thanks for the time, thank you and hug!