Count number of words - C++ Program

Q. Write a C++ program to count total number of words used in any sentence.


Following program is counting total numbers of words used in a string.

using namespace std;
int main()
        char strs[100], countw=0, i;
        cout<<"\n Enter String : ";
        int len=strlen(strs);
        for(i=0; i<len; i++)
                if(strs[i]==' ')
        cout<<"\n Total Number of Words in String are : "<<countw+1;
        return 0;


count word