功能按名称和国家搜索

时间:2012-05-11 13:07:36

标签: c++ search

当我将其更改为按点或其他整数搜索时,它正在工作,但我必须按名称和国家搜索。该函数正在检查已包含数据的数组。

void search (competitor competitors[], int number)  
{
if(number==0)
{
    cout<<"\n Array is empty!!!\n";
    return;
}

char country[50];
char name[50];
char choice;
bool flag;

do{
    cout << "\n\n Enter country: " << endl;
    cin >> country;
    cout << " Enter name: " << endl;
    cin >> name;

    flag = false;

    for(int i=0; i<number; i++)
    {
        if( country==competitors[i].country && name==competitors[i].name)
        {
            count << " Competitor found!" << endl;
        }
    }
    if (flag == false)

    cout << " Want to search again(Y/N)?: ";
    cin >> choice;

}while(choice == 'Y' || choice == 'y');

}

1 个答案:

答案 0 :(得分:2)

我假设competitors[i].country (name)char[]

您无法使用char[]比较==数组(比较数组的基地址,而不是内容),您必须strcmp()。或者,因为这是C ++,使用std::string代替char[]并使用==