need help with string output
I am having this little problem with my code. I am trying to print the longest word in a paragraph. Within my IF statement, the words print ok (words are printed until the biggest word is found) but when the program ends, the word printed is the last word of the paragraph. I've tried with a character array and with pointers. I think a pointer may be needed here, although I don't know much about them. I've tried other ways as well but I just can't figure it out.
Any comment would be appreciated.
As well can anyone tell me how to format my code properly on this board? When I copy and paste it looks fine but when I preview it, everything is right justified.
void words(int &word_count, float &ave_len) // Counting the words
int len=0, temp=0;
infile.open ("parag2.txt", ios::in);
infile >> word;
if (len>temp) // checking for longest word
cout << word;
cout << temp1; // THIS PRINTS THE WORDS OK
total_len=len+total_len; // total for all words
} // END WHILE
cout << temp;
cout << temp1; // THIS GIVES ME THE LAST WORD IN THE PARAGRAPH
ave_len=float(total_len/word_count); // Average lenght of the words that will be passed
// to other function for printing
} // END WORDS