#include <iostream>
using namespace std;
int syn(char *pc[], char, int);
int main()
{
char *pc[20];
char ch;
cout<<"Type the text" << endl;
cin>>*pc;
cout<<"Type The character:" << endl;
cin>>ch;
int apotelesma = syn(&pc[0], ch, 20);
cout<< "There are " << apotelesma << " " << ch << endl;
system("pause");
return 0;
}
int syn(char *pc[],char ch, int n){
int i;
int metroitis=0;
for (i=0; i<n; i++){
if (*pc[i]==ch){
metroitis++;
}
}
return metroitis;
}
有人可以告诉我什么是错的吗?当它进入if子句时它没有响应。字符数组和指针
你确定你想要一个指向字符的指针数组吗?它看起来像你只是像字符数组一样使用它。 – chris
我想你只需要一个字符数组:char * char [20],而不是char * pc [20] –
是的,你是对的,这是我的一个错误。我想让我的数组[20]函数。然后在函数syn中,我想对数组进行搜索。现在我改变了syn: int syn(char * pc,char ch,int n)但是它在if循环中有错误。 一元类型参数无效* –