It it simple to find the number of characters in the longest word, but I am having difficulty printing the word with the longest number of characters. Any algorithm suggestions?
It it simple to find the number of characters in the longest word, but I am having difficulty printing the word with the longest number of characters. Any algorithm suggestions?
If you already know it's length, and where it starts, then all you need is a for loop.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
1) Separate string by words.
2) For each word, check the length of it.
3) If the length of the one you're checking > the longest word you already looked at, then save this one to be the longest word.
4) When you're done searching all of the words, you have the longest word already.