Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- char* longest_word(char *phrase)
- {
- int counter = 0;
- int max_length = 0;
- int index = 0;
- for(int i = 0; phrase[i] != '\0'; i++)
- {
- if(phrase[i] != ' ')
- {
- counter++;
- }
- else if (counter > max_length)
- {
- max_length = counter;
- index = i ;
- counter = 0;
- }
- }
- return phrase + index;
- }
- int main()
- {
- char phrase[20];
- cin>>phrase;
- cin.getline(phrase, 20);
- cout<<longest_word(phrase);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment