#include<iostream>
using namespace std;
size_t GetNumberOfWords(const char* text)
{
size_t count = 0;
while(*text)
{
//перематываем все пробельные символы
while(*text && isspace(*text) ) ++text;
//если перемоталась вся строка - закончить работу
if(!(*text) ) break;
//если мы здесь, значит мы наткнулись на "слово"
//увеличиваем счетчик слов, и перематываем его
++count;
while(*text && !isspace(*text) ) ++text;
}
return count;
}
int main()
{
enum { eSIZE = 100};
const char test1[eSIZE] = " Hello word hello word";
const char test2[eSIZE] = "Hello word hello word";
const char test3[eSIZE] = "Hello word hello word";
const char test4[eSIZE] = "Hello word hello word ";
cout<<'\n';
cout<<"WELCOME TO TEST OF FUNCTION size_t GetNumberOfWords(const char* text); \n";
cout<<"source text :"<<test1<<endl;
cout<<"number of words in the text = "<< GetNumberOfWords(test1)<<endl<<endl;
cout<<"source text :"<<test2<<endl;
cout<<"number of words in the text = "<< GetNumberOfWords(test2)<<endl<<endl;
cout<<"source text :"<<test3<<endl;
cout<<"number of words in the text = "<< GetNumberOfWords(test3)<<endl<<endl;
cout<<"source text :"<<test4<<endl;
cout<<"number of words in the text = "<< GetNumberOfWords(test4)<<endl<<endl;
cout<< "THE CORRECT RESULT SHOULD BE: 4 WORDS\n";
return 0;
}