Hey guys, I think I have a pretty simple fix here, I just need somebody to point out my error.
I'm getting a seg fault after writing to an array of char. I need my function to run through the array and find pairs. If every char in the array has a pair, return true. After my program acepts values into the array, it segfaults. Heres my code...

bool allValuesArePaired(char d[], int o)        //int o is equal to const int (EVEN = 6)
{
	int count, tracker, i, j;
	cout << "Fill array to check parity\n";
	
	for (i = 0; i < EVEN; i++) 
	{
		d[i] = 0;
		cin >> d[i];
	}
	
	for (i = 0; i < EVEN; i++)
	{
		for (j = 0; i < EVEN; j++)
		{
			if (d[i] == d[j])
			{
				count++;
				cout << count;
			}
			if (count == 2) 
			{
				count = 0;
				tracker++;
			}
		}
	}
		
		if (tracker >= EVEN / 2) 
		{
			return true;
		}
		else 
		{
			return false;
		}

}

Line 15: the bound on the loop is wrong.. simple typo, you wrote i where it should be j:

for (j = 0; i < EVEN; j++)
//should be:
		for (j = 0; j < EVEN; j++)

A very simple fix indeed. Thanks! +rep

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.