數據結構課程的c++測試題,引用的知識點。
設計一個classifier()函數。
int main()
{
int tnum(0),tcap(0),tlow(0);
cout << "input: " << endl;
char ch;
cin >> ch;
while(ch!='#')
{
classifier(ch, tnum, tcap, tlow)++;
cin >> ch;
}
cout << "number: "<<tnum<<',';
cout << "capital letters: "<< tcap<<',';
cout << "lower case letters" << tlow <<endl;
return 0;
}
一開始我的代碼是這樣的
int& classifier(char ch, int tnum, int tcap, int tlow);
錯誤:segment fault
改正:
int& classifier(char ch, int& tnum, int& tcap, int& tlow);