-1
I came across this problem during a personal project, it is more curiosity really, I would like to ask anyone who can give me a light on this, because I have solved the problem in other languages only in C that not yet.
How can I detect the largest word of a string in the case of a phrase typed by the user? I’m having trouble with the part when I detect the first white space, inside the 'If' 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’t go on, I don’t know how to keep comparing and he always gives me back the last word of the sentence, never the greatest. I have tried to assemble proper functions for when detecting the first space, it validates the string up to that point and copies to another char string, but came to nothing.
If someone has a solution, I was only able to solve this with the JAVA function that calls Split that fragments the string into an array with each Input being a word, then it is easier to compare. I can’t imagine if something like this can be done in C. More to heal this curiosity of mine that I come here. Thank you for taking the time, thank you and hug!