Search for Struct item & display Struct

May 26, 2017 at 12:14am
I have an assignment which is almost complete, but I can't seem to identify how to find one item in a struct, and display the total struct contents associated with the item. Specifically, I provide the name of an event, and the event details are displayed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void Search(int len, char name[])
{
	activity names;
	int i;

	cout << "Activity.";
	cin.get(names, DESC, '\n');
	cin.ignore(300, '\n');

	for(int i = 0; i < len; ++i)
	{
		if(strcmp(names && name)==0)
			cout << name[i];
	}
}


I've tried several versions and forms of this; this was my latest.
variable name comes from my activity struct.
My cout is generic because I've rewritten so many times.

Help!
May 26, 2017 at 8:31am
What is activity? If you have multiple items there should be a container/array in order to hold this items.

Line 12 should look like this:

if(strcmp(names, name)==0) // && makes no sense

The loop this way doesn't make sense either. It should iterate through the item container.
May 26, 2017 at 5:24pm
You haven't shown the declaration for activity, although you imply it is a struct.
Based on that, you can't do a cin to a struct (line 7).

Line 12: As coder777 said, your call to strcmp makes no sense. strcmp requires two arguments. You're giving it only one argument which is the logical AND of a struct and the address of a char array. Again, that makes no sense.

Line 13: You're outputting a single character at a time. Why wouldn't you eliminate the loop and just:
 
  cout << name;

Topic archived. No new replies allowed.