用户输入的句子,我想要计算其中没有任何单词 例如:Shsssssssssh ......我正在寻找wabbits。嘿嘿嘿嘿...... 我得到的话,但我不想数(...)
string sentence ;
char space[] = " " ;
int noWords = 0;
while(getline(cin , sentence) )
{
noWords = 0;
char* arr = new char[sentence.length()];
for (int i = 0; i <sentence.length(); i++)
{
arr[i] = sentence[i];
}
char* token;
token = strtok(arr , space);
while (token != NULL)
{
noWords ++;
token = strtok(NULL , space);
}
cout<<noWords<<endl;
}