nested for loop isn't initializing my char[]

When my code runs through this loop I made to compare two strings it doesn't initialize my char[] with the new values. I still get the output of "xxxxx" instead of what I want. I've debugged it and walked line by line and can't spot where the initializing is canceled.

maybe there is a better way of doing this comparison. I'm required to convert it back to a string no matter what so I was trying to just compare the two keeping them as a string. ultimately if i could figure out why my char temp[] isn't being set to the new values I could finish this assignment and turn it in.

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
  char temp[5] = { 'x', 'x', 'x', 'x', 'x' };

	//checks for win
	if (comp.a == player.a)
	{
		a = true;
	}

	//compare loop start
	for (int i = 0; i < 5; i++)
	{
		if (comp.a[i] == player.a[i] && temp[i] != 'x')//checks to see if value is correct at right position
		{
			temp[i] = '1';
		}
		for (int j = 0; j < 5; j++)
		{

			if (comp.a[i] == player.a[j] && temp[i] != 'x')
			{
				temp[i] = '2';
			}
			for (int y = 0; y < 5; y++)//checks for wrong value
			{
				if (comp.a[i] == player.a[y] && temp[i] != 'x' && y == 4) // y = 4 prevents it from initializing till the whole string has been compared.
				{
					temp[i] = '0';
				}
			}
		}
	}
	//end compare loop

	won.a = string(temp, 5);

	cout << won.a << endl;
	system("PAUSE");
Lines 12, 19, and 25 will always fail, because temp[i] != 'x' fails. Since they fail, there are no assignments to temp and the situation remains the same.
don't know why i didnt see this. I may have to rethink my for loops for comparison.
Topic archived. No new replies allowed.