0

Could please help me in the code,of how to extract the no of words in each sentence(if there are 2 or more sentence).But i want the code to use string function?????????

3
Contributors
7
Replies
8
Views
9 Years
Discussion Span
Last Post by Ancient Dragon
0

if you post the code that YOU have tried then we can help you in debugging and solving the problem. but you cant just expect spoon feeding here..

ps: i just got ripped left-right-center for trying to solve a similar thread

0

I read abt token function but i dnt knw how to use it.please help?????????

int a,b=0;

for(a=0;a<sr1.length();a++)
{
if (st1[a]
{
b++;
}
}

cout<<endl;
cout<<"number of words in a sentence<<endl;
cout<<endl;

0

if you post the code that YOU have tried then we can help you in debugging and solving the problem. but you cant just expect spoon feeding here..

ps: i just got ripped left-right-center for trying to solve a similar thread

I read abt token function but i dnt knw how to use it.please help?????????

int a,b=0;

for(a=0;a<sr1.length();a++)
{
if (st1[a]
{
b++;
}
}

cout<<endl;
cout<<"number of words in a sentence<<endl;
cout<<endl;

0

'strtok' returns tokens in the string. Basically you put it in a loop, give the input string and a delimiter as arguments, it'll keep returning each token. you can put a counter and check for NULL token to exit the loop. for function signature try reading some doc.

0

and yes make sure you read the 'things to keep in mind' while using strtok or the result would be unexpected... dont want to tell you and spoil the suspense :)

0

It is easier to use std::stringstream class to do that

#include <sstream>
<other includes here>

...
string sentence = "Once upon a time there were three little pigs";
string word;
vector<string> array;
stringstream stream(sentence);
while( stream >> word)
{
    array.push_back(word);
}
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.