#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循環中有錯誤。 一元類型參數無效* –