编写一个函数,统计一条英语句子中字母的个数,在主程序中实现输入输出。
#include <iostream>
#include <String>
using namespace std;
int count(char *str){
int n=0;
for(int i=0;str[i];i++){
if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z')){
n++;
}
}
return n;
}
int main(){
char str[100];
cout<<"please input an English sentence:";
gets(str); //gets()可以输入空格' ',但是cin不能输入空格;
cout<<count(str);
return 0;
}