Can't Figure out where my loops are going wrong

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;
}
Well, I seem to have problems with for statements, but I think the problem may be at line 13
for(startScan = 0; startScan = (NUM_NAMES - 1); startScan++), the startScan = (NUM_NAMES - 1) part I think. Here you have an assigment or initialization, it is supposed to be a condition, so
startScan == (NUM_NAMES - 1) for example *note*that might not be what it is supposed to be, it might be <, >, !=, <=, >= or something else, I'm not sure.
Danny- the condition in the middle is the condition that must be true for the loop to continue, not to end. So, probably < or <=, depending on how NUM_NAMES is defined.
Okay, so that is likely the problem though, the fact that the person used a single = not a conditional operator?
wow, i just missed the < instead of =. Thanks. My original purpose was to arrange the names in alphabetical order, but this isnt working. could you tell me what is wrong with the actual code?
Topic archived. No new replies allowed.