第二周实验报告(三)

来源:互联网 发布:洗衣机知乎 编辑:程序博客网 时间:2024/06/05 02:20

#include <iostream>
#include "string.h"
using namespace std;
void check_word(char ch[100]);
int count=0;
int main()
{
    char ch[100];

    cin.getline(ch,100);

    check_word(ch);

   cout<<"There are "<<count<<" words in the line."<<endl;

   return 0;
}
void check_word(char ch[100])

{

     for(int i=0;ch[i]!='\0';i++)
        {
           if((ch[i]==' '||ch[i]==','||ch[i]==';'||ch[i]=='.'||ch[i]=='!'||ch[i]=='?')&&ch[i+1]!=' ')count++;
        }   
}

原创粉丝点击