求修改,可读取空格 数字与字符,cin 无法读取空格,就是不会修改
程序代码:
#include<iostream> #include<string> using namespace std; void search(char *s,char c[]); int main() { char string[100]; cout<<"please enter string:"<<endl; cin>>string; char *p; p=string; search(p,string); return 0; } void search(char *s,char c[]) { int i; int a=0,b=0,f=0,d=0; int stren=0; s=c; while(*s!='\0') { s++; stren++; } for(i=0;i<stren;i++) { if((c[i]>='a'&&c[i]<='z')||(c[i]>='A'&&c[i]<='Z')) { a++; } else if (c[i]>=0&&c[i]<=9) { b++; } else if(c[i]==' ') { f++; } else { d++; } } cout<<"字母的个数:"<<a<<endl; cout<<"数字的个数:"<<b<<endl; cout<<"空格的个数:"<<f<<endl; cout<<"其它的个数:"<<d<<endl; cout<<endl; }