Search string?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2006
Posts: 6
Reputation: hellokitty88 is an unknown quantity at this point 
Solved Threads: 0
hellokitty88 hellokitty88 is offline Offline
Newbie Poster

Search string?

 
0
  #1
Mar 16th, 2008
I am trying to do a sequential string, but when I run my program I recieve three errors:the first one talks about 'searchList' : cannot convert parameter 3 from 'const char [4]' to 'std::string []
( I tried putting code tags by inserting my code between the , but I am not positive if it is displaying) Sorry for any convenience!

  1.  
  2. #include <iostream>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int searchList(string array[], int, string value[]);
  9. const int ARRAY_SIZE = 3;
  10.  
  11. int main()
  12. {
  13. string someArray[ARRAY_SIZE] = {"mouse", "cat", "ant"};
  14. int results;
  15. results = searchList(someArray, ARRAY_SIZE, "ant");
  16.  
  17. if (results == -1)
  18. cout << "You did not earn 100 points on any test\n";
  19. else
  20. {
  21. cout << "You earned 100 points on test ";
  22. cout << (results + 1) << endl;
  23. }
  24. return 0;
  25. }
  26. int searchList(string array[], int numElems, string value[])
  27. {
  28. int index = 0; // Used as a subscript to search array
  29. int position = -1; // To record position of search value
  30. bool found = false; // Flag to indicate if the value was found
  31. cout << "made it here" << endl;
  32. while (index < numElems && !found)
  33. {
  34. if (array[index] == value[]) // If the value is found
  35. {
  36. found = true; // Set the flag
  37. position = index; // Record the value's subscript
  38. }
  39. index++; // Go to the next element
  40. }
  41. return position; // Return the position, or -1
  42. }
Last edited by hellokitty88; Mar 16th, 2008 at 5:42 am. Reason: code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,362
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Search string?

 
0
  #2
Mar 16th, 2008
remove the brackets from the last parameter -- it should not be an array
int searchList(string array[], int numElems, string value);
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC