Finding the greater word

The issue with your code is that you don’t reset temp1 on every word. That is:

  1. You read the word Goodness: temp2 is now Goodness
  2. You read the word Of. This is larger than Goodness, so temp2 is now Of
  3. You read the word Grace. This is smaller than Of, so temp2 stays Of
  4. You read the word Come. However, you did not clear temp1 after reading Grace. So, temp1 is now GraceCome. Since temp1 is never cleared, but more letters is added to its end, it will keep being smaller than Of.

So, you need to make temp1 = "" unconditional on wheter temp1 < temp2:

        if isletter(ch)
            temp1 *= ch
        elseif isspace(ch)
            if temp1 < temp2
                temp2 = temp1
            end
            temp1 = ""
        end    
2 Likes