字符串中单词的个数

来源:互联网 发布:日本男装品牌 知乎 编辑:程序博客网 时间:2024/06/06 14:28
#include<iostream>using namespace std;int main(){    char cstring[100];    int index, iword = 1;    char blank;    gets(cstring);    if (cstring[0] == '\0')    {        cout << "there is no char" << endl;    }    else        if (cstring[0] == ' ')            cout << "the first char is a blank" << endl;        else        {            for (index = 0; cstring[index] != '\0'; index++)            {                blank = cstring[index];                if (blank == ' ')                {                    iword++;                }            }            cout << "the words number is " << iword << endl;        }    system("pause");    return 0;}
0 0
原创粉丝点击