I'm a C++ student, and I'm almost there on this assignment, except I can't get the search function to work correctly. The search function should accept a search input from the user, then list all the items related to that input. In this case, its all the tasks related to a particular course. When I enter tasks I can list them, and the search function appears to work, but won't display output. The program compiles and otherwise works OK. I can provide the full 325 lines of code if that would help.
Two pieces of relevant code are the search function and the the search function call which is where the output of the function is supposed to be. I can't tell whether the problem is that the search isn't populating the matches array, or that the output code is somehow borked.
Thanks for any pointers. I'd really like to understand what I'm doing wrong here.
RELEVANT SEARCH CODE:
bool searchEntry(const char name[], TaskRecord matches[], int& matchesSize, const TaskRecord list[], int listSize)
{
int index;
for(index=0; index < listSize; index++)
{
if(strcmp(name, list[index].course) == 0)
{
strcpy(matches[index].course, list[index].course);
strcpy(matches[index].task, list[index].task);
strcpy(matches[index].date, list[index].date);
break;
}
}
if (index == listSize)
return false;
else
return true;
}
[B]Relevant Output Code: [/B]
void processCommand(char command, TaskRecord list[], int& listSize)
{
TaskRecord entry;
TaskRecord matches[MAX_CHAR];
char name[MAX_CHAR];
int matchesSize;
//... skip ahead to relevant section
case 's': readInName(name);
if(searchEntry(name, matches, matchesSize, list, listSize))
{
cout << endl << "The Tasks for Course " << name << " are: " << endl;
// column titles
cout << setw(TASK_COL_WIDTH) << " Task"
<< setw(DATE_COL_WIDTH) << " Date " ;
cout << endl << endl;
// column content
for(int index=0; index < matchesSize; index++)
{
cout << setw(TASK_COL_WIDTH) << matches[index].task
<< setw(DATE_COL_WIDTH) << matches[index].date
<< endl;
break;
}
}// end if
else
cout << endl << "There are no Tasks for " << name << " ." << endl;
break;