字符串:计算单词

来源:互联网 发布:网络位置是什么 编辑:程序博客网 时间:2024/04/16 22:37
#include<iostream>#include<cstring>using namespace std;int main(){int count,state;char *p;count=0;state=1;char s[50];cout<<"请输入一些文本"<<endl;cin.get(s,50);p=s;while(*p!='\0'){if(*p==' ')state=1;else if(state==1){state=0;count++;}p++;}cout<<"单词数是"<<count<<endl;return 0;}

0 0