The issue with your code is that you don’t reset temp1 on every word. That is:
- You read the word
Goodness:temp2is nowGoodness - You read the word
Of. This is larger thanGoodness, sotemp2is nowOf - You read the word
Grace. This is smaller thanOf, sotemp2staysOf - You read the word
Come. However, you did not cleartemp1after readingGrace. So,temp1is nowGraceCome. Sincetemp1is never cleared, but more letters is added to its end, it will keep being smaller thanOf.
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