내 선형 검색 기능은 검색된 항목이 아닌 데이터의 첫 번째 항목 만 반환합니다. 저는 C++에서 신입생이고 문자열 라이브러리를 사용하는 것이 금지되어 있습니다. 내가 뭘 잘못하고 있다고 말할 수 있습니까? 호출 될선형 검색 기능에 문제가 있습니다. C++
// 함수 자체 ....
bool searchDB(const char key[], const Course list[], int size, int (matches) [MAX_CAP], int& matchesSize)
{
bool found = false;
int index;
matchesSize= 0;
for (index = 0; index < size; index++)
{
if (strcmp(key, list[index].name) == 0)
{
matches[matchesSize] = index;
matchesSize++;
found = true;
}
}
return found;
}
// ...
void executeCmd(char cmd, Course list[], int& size)
{
Course course;
switch (cmd)
{
case 's':
int i;
char name[MAX_CHAR];
int matches[MAX_CAP];
int matchesSize;
cout << "Please enter the name of the Course you want to search: ";
getString(name, MAX_CHAR);
if (searchDB(name, list, size, matches, matchesSize))
{
for (i = 0; i < matchesSize; i++)
cout << "Match found: " << list[i].name << '\t' << list[i].task << '\t' << list[i].date << endl;
}
else
{
cout << "No match found!" << endl;
}
break;