#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
//5、统计一个一篇英文小说的单词数,从文件读取小说
int main()
{
ifstream input;
input.open("a.txt");
char strword[1024];
int count=0;
input.getline(strword,1024);
while(strword[0]!='\0'){
for(int i=0;i<strlen(strword);i++){
if(strword[i]==' ') count++;
if(strword[i]=='.') count++;
if(strword[i]=='?') count++;
if(strword[i]=='!') count++;
if(strword[i]==',') count++;
if(strword[i]==';') count++;
if(strword[i]==';') count++;
}
input.getline(strword,1024);
}
cout << count << endl;
return 0;
}
c++ 统计一个一篇英文小说的单词数,从文件读取小说
最新推荐文章于 2023-04-12 12:06:29 发布