Searching for names in an array

I have an assignment in which I need the user to enter names into an array, sort it, ask for a string to search for, and provide an index for the string if it is in the array. The user can either enter 20 names or press the enter key to stop entering names early. The names have no character limit, so we are supposed to use an array of pointers.

What I have so far is...
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  void main()
{

	int	 index;
	int i;
	string * Names[20];
	bool typenames;
	char find;

	cout << "Type up to 20 names, press enter to stop." << endl;

	typenames = true;

	do{
		for (i = 0;i < 20; i++)
		{
			cin >> Names[i];
		}

		//if enter is pressed typenames=false

		typenames = false;
	} while (typenames);



	cout << "Before sort" << endl;
	for (i = 0; i < 20; i++)
	{
	        cout << Names[i] << endl;
	}

	BubbleSort(Names[], strlen(Names[]));
	
	cout << "After sort" << endl;
	for (i = 0; i < 20; i++) 
	{
		cout << Names[i] << endl;
	}

	//index = BinarySearch(Names, find, i-1);
	//cout << "Index is " << index << endl;

	system("pause");
}


We were also given some basic functions within the past few weeks that sort and search, but I have had a difficult time figuring out how to pass the arrays into them properly. Obviously they need to be altered as well to complete the program but I haven't even attempted that yet.

Sort function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void BubbleSort(char Array[], int NumChars)
{
	int		i;
	bool	Sorted;
	char	Temp;

	do	{
		NumChars--;
		Sorted = true;
		for (i = 0; i < NumChars; i++)
			if (Array[i] > Array[i + 1])
			{
			Sorted = false;
			Temp = Array[i];
			Array[i] = Array[i + 1];
			Array[i + 1] = Temp;
			}
			else;
	} while (!Sorted);
}


Search function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int BinarySearch(char Array[], char c, int NumElements)
{
	int		First;
	int		Middle;
	int		Last;

	First = 0;
	Last = NumElements - 1;
	while (First <= Last)
	{
		Middle = (First + Last) / 2;
		if (c == Array[Middle])
			return Middle;
		else
			if (c < Array[Middle])
				Last = Middle - 1;
			else
				First = Middle + 1;
	}
	return -1;
}


Help would be very much appreciated.
Topic archived. No new replies allowed.