R6010 - abort() has been called

I am working on an assignment for my c++ class and when I run my program and get to a certain point I get an error message that says R6010 - abort() has been called and I can't figure out why. The program reads in a number then allows the user to enter that many names. The names have no spaces. Then the program calls a function, in my case string namesSorted(string names[20][15], int numOfNames), to sort the names in alphabetical order. When it calls the function I get the error so there is probably something wrong with the sorting but I haven't been able to try and fix it because I don't know how to fix the error.

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>
#include <string.h>
#include <string>

using namespace std;

string namesSorted(string names[20][15], int numOfNames);

void main()
{
	string names [20][15];

	int numOfNames;
	int currentNum;
	double dCurrentNum;
	int k = 1;

	const	long	MaxCharsPerName	(15);

	bool howMany = false;
	bool nameCheck = false;

	cout << "How many names would you like to enter? 20 is the max. Please do not use spaces when entering the names." << endl;
	

	do{
	
		cin >> numOfNames;

		if(numOfNames > 20 || numOfNames < 1)
		{
			cout << "Please enter a number between 1 and 20." << endl;

			howMany = false;
		}
		else
		{
			break;
		}

	} while(!howMany);


		for(int i = 0; i < numOfNames; i++)
		{

			for(int y = 0; y < 15; y++)
			{

				for(int z = 0; z < numOfNames; z++)
				{
					cout << "Please enter name " << k << ": ";
					cin >> names [z][y];
					k++;
				}

				break;
			}

			break;

		}
	


	cout << "The names entered were: " << endl;

	for(int j = 0; j < numOfNames; j++)
	{
		for(int k = 0; k < 15; k++)
		{
			cout << names[j][k];
		}
		cout << endl;
	}

	namesSorted(names, numOfNames);

	cout << "The names in alphabetical order are: " << endl;

	for(int z = 1; z <= numOfNames; z++)
	{
		cout << names[z] << ", ";
	}
}

string namesSorted(string names[20][15], int numOfNames)
{


	bool namesSortedCheck;

	string namesSorted[20][15];

	for(int y = 0; y < 15; y++)
			{

				for(int z = 0; z < numOfNames; z++)
				{
					namesSorted[z][y] = names [z][y];
				}

			}
	return namesSorted[20][15];
	
}


I have debugged with step over and it works until the namesSorted(names, numOfNames); line. Any ideas?
Topic archived. No new replies allowed.