Question: Can someone explain why my code isnt working. It is not returning the largest/smallest word. C++ Here is my code //split.cpp #include #include #include #include

Can someone explain why my code isnt working. It is not returning the largest/smallest word. C++

Here is my code

//split.cpp #include #include #include #include #include

using namespace std;

void split ( string & text, string & seperators, list & words) //split a string into a list of words //text and seperators are input //list of words is output { int textLen = text.length(); int start = text.find_first_not_of(seperators, 0); //loop as long as we have a non-separator character while((start >= 0) && (start textLen)) stop = textLen; //pushback the words int list words.push_back(text.substr(start, stop-start)); start = text.find_first_not_of(seperators, stop+1); } }

int main() { string line; string smallest = ""; string largest = ""; string sep = " .,?!"; list words; cout ::iterator current; list::iterator stop = words.end(); for(current = words.begin(); current != stop; ++current) cout largest) largest = *current; } cout

This is the output.

Can someone explain why my code isnt working. It is not returning

emmang:/workspace $ g++ split.cpp emmang:/workspace$./a.out Please Enter a line. This is a test for sentences This is test for sentences smallest word: largest word: test emmang:~/workspace $

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!