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;

you have to read the source and understand it.

However I have review your code and the bug trouble is here.

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;
}

You copying the matched record 'index' in list to 'index' in matches.It's wrong.
Instead you should have another integer to count current number of matches.

And you also should insert failsafe code to detect a possible overrun of the
arraysize. And at last you should set matchesSize to the number of matches.Or you
can return it. return 0 for not found.


Next time go through your code line by line , believe me it will make you a good
programmer.

TaskRecord		matches[MAX_CHAR];

And ^ code also problematic too. MAX_CHAR as it sounds it's typically used for a char array.
I'm suggesting a name , may be.

#define MAX_NUM_RECORDS    1024  // let's assume 
...
       TaskRecord     matches[MAX_NUM_RECORDS];
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.