using find

I apologize for being vague and only posting partial code but my assignment is complete except for this one thing. I am making a program that searches a library and returns only the books that partially or completely match the authors name. currently my program always returns all of the books.

I think the problem lies in line 21. no matter what I type the program returns the entire library. I think that find is always returning true. however I have no idea what to do to make the program only print matches of partial strings...
any help is appreciated and am I on the right track?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 

void actions (char response, int lineCount)
 {
	int index = 0;
	char search [256];
		
		response = toupper(response);
	
	switch (response)
	{
		
		case 'A':
			cout << "you selected search by (A) author \n";
			cout << "please enter the author you would like to find";
			cin >>  search;
			
			for (index =0; index < lineCount; index ++)
		
				 
			if (bookAuthor[index].find(search))
			{
					 cout << bookTitle[index] << "(" << bookAuthor [index] << ")\n"	;
				}
			 
Last edited on
I don't know if this will work, but perhaps replace line 21 with
if (bookAuthor[index].find(search))
thats how it is in my code, let me change that
if find() it the function of string look at this:

http://www.cplusplus.com/reference/string/string/find/

find() would only return 0 if it finds something it at the very beginning. if it can't find anything it returns npos:

http://www.cplusplus.com/reference/string/string/npos/
Thanks
Topic archived. No new replies allowed.