void main() { char a[100]="I am a student!"; int num=0; int i=0; char c='a'; cout<<"input the str"<<endl; while((a[i]=getchar())!='\n') { i++; } cout<<"what do you want to find?"<<endl; cin>>c; int n=0; while(a[n]!='\0') { if(a[n]==c) { num++; n++; } else { n++; } } cout<<num<<endl; } vc6.0下编译通过,vc下用cin输入字符串的时候遇到空格就停止了,所以用getchar()来输入字符串
|