How to count number of words in a string in C/C++

preview_player
Показать описание
Thank you for your support!
Рекомендации по теме
Комментарии
Автор

Wow thanks for this video cos I tried to do it 4 hours but it failed before I watch the video .good keep it up

reactvotes
Автор

Can you show us how to return a single word that we have counted?

andrewburke
Автор

so what do you get doing *pStr? the actual character? And what do you increment if you do pStr++? the address of the pointer? Further on I dont get the line where you check ++len == 1, would be nice if you could explain a little more in detail. Thank you.

florent
Автор

what if the word was one caractere like i am hungry its count 2 words

aminebenmoussa
Автор

Can this be applied to pattern matching as well ?

cadetxero
Автор

can you teach us how to make scripts, use mouse function to find specific color or thing on screen and move to that location and have it click and other stuff? thx

ObtecularPk
Автор

Plzzz makee this program convert of numbers in to words in c programming
Like 5347 five thousand three hunndered and forty seven

hoorkhan
Автор

what does this expression mean else if (++len == 1 )

tomyang
Автор

#include <iostream>
#include <string>

using namespace std;

int wordCount(const string& str);


int main()
{
string str = "How are you?";
cout << wordCount(str) << endl;
return 0;
}

int wordCount(const string& str)
{
int i(0);
bool b(false);

str.empty()? b : b =true;

if (b)
{
i = 1;
for(const char& c : str)
{
if(isblank(c))
{
i++;
}
}
}
return i;
}

Luca_cata