I'm relatively new to C++, and was trying to write a simple linear search function to search through an array of strings to determine at which point a new string could be added.
Here is the code so far:
Code:
#include <iostream.h>
int searchList(char[], int, char);
const int arrSize = 5;
void main(void)
{
char tests[arrSize][15] = {"Jeremiah", "David", "Timothy", "Samuel"};
int results;
results = searchList(tests[], arrSize, '\0');
if (results == -1)
cout << "There is no room left in the array!";
else
{
cout << "Space ";
cout << (results + 1) << " is available." << endl;
}
}
int searchList(char list[], int numElems, char value)
{
int index = 0;
int position = -1;
bool found = false;
while (index < numElems && !found)
{
if (list[index] == value)
{
found = true;
position = index;
}
index++;
}
return position;
}
And I keep getting the following error:
error C2059: syntax error : ']'
The point at which the error is encountered is:
Code:
results = searchList(tests[], arrSize, '\0');
Now, if I delete the brackets, I get:
error C2664: 'searchList' : cannot convert parameter 1 from 'char [5][15]' to 'char []'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
And if I has a second pair of brackets, I get:
error C2059: syntax error : ']'
again.
So where's my problem? If anyone could help, that would be great. Thanks!