Cant figure out this infinite loop

I am trying to use the selection sort method to sort a 2d array of names. The program runs but seems to be stuck in a loop somewhere. If anyone could help tell me where the loop is stuck?


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
int main()
{
	const int NUM_NAMES = 20, SIZE = 17;
	char names[NUM_NAMES][SIZE] = { "Collins, Bill", "Smith, Bart", "Allen, Jim",
									"Griffin, Jim", "Stamey, Marty", "Rose, Geri",
									"Taylor, Terri", "Johnson Jill", "Allison, Jeff",
									"Looney, Joe", "Wolfe, Bill", "James, Jean",
									"Weaver, Jim", "Pore, Bob", "Rutherford, Greg",
									"Javens, Renee", "Harrison, Rose", "Setzer, Cathy",
									"Pike, Gordon", "Holland, Beth" };
	int startScan, minIndex;
	char minValue[SIZE];
	for(startScan = 0; startScan = (NUM_NAMES - 1); startScan++)
	{
		minIndex = startScan;
		for(int i = 0; i < SIZE; i++)
			minValue[i] = names[startScan][i];
		for(int index = startScan + 1; index < NUM_NAMES; index++)
		{
			if(names[index][0] < minValue[0])
			{
				for(int i = 0; i < SIZE; i++)
					minValue[i] = names[startScan][i];
				minIndex = index;
			}
		}
		for(int i = 0; i < SIZE; i++)
			names[minIndex][i] = names[startScan][i];
		for(int i = 0; i < SIZE; i++)
			names[startScan][i] = minValue[i];
		
	}
	for(int i = 0; i < NUM_NAMES; i++)
	{
		for(int j = 0; j < SIZE; j++)
			cout << names[i][j];
		cout << endl;
	}
	return 0;
}
Classic :):
for(startScan = 0; startScan = (NUM_NAMES - 1); startScan++)

for(startScan = 0; startScan == (NUM_NAMES - 1); startScan++)
startScan = (NUM_NAMES - 1) is an assignment. startScan will receive the value 19 and that will be treated as a boolean, making it always true.

Edit: Wait, even with '==' that doesn't make sense. Did you mean '<'?
Last edited on
Yes, i meant ">". That was a simple mistake. THANKS!
Topic archived. No new replies allowed.