编写程序实现一个字符串查找指定的字符,并输出指定的字符在字符串中出现的次数及位置,如果该字符不包含指定的字符,请输出提示信息;
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int N = 10000;
int main(){
int cnt, res[N];
char arr[N], temp;
cout<<"please input string:"<<endl;
cin>>arr;
cout<<"please input char:"<<endl;
cin>>temp;
cnt = 0;
for(int i=0; i<strlen(arr); ++i){
if(arr[i] == temp){
res[cnt++] = i;
}
}
if(cnt == 0){
printf("it's not char in the string!");
return 0;
}
printf("count = %d\nlocation = ", cnt);
for(int i=0; i<cnt; ++i){
printf("%d ", res[i] + 1);
}
return 0;
}