# Thread: Comparing 2 char arrays

1. ## Comparing 2 char arrays

im in the final stages of writing mastermind and im down to the white pegs
i have 2 char arrays with 4 elements in each i.e

userguess

i need to compare them with each other so if the user guesses for example R i need to search through answer and see if there are any R's more importantly which location they are in and if they are in the same location i.e

userguess = 'R'

if they are in the same location i need to ignore it as that would generate a black peg however if they are in different locations i.e

userguess = 'R'

then i need to add 1 to my white count. I got that working however my problem comes when there is more than 1 'R' in answer[x] i tried using the following method which went wrong

etc.......

i know thats not the correct syntax! somehow i think i need to change it so if answer1, 2 or 3 are the same it deducts 1 from the white count? i tried this with lots of if statements it compiled but crashed every time it tried to work out the white count. i would post my code but its seriously long. Can anyone point me in the right direction even if its a different way of doing it sorry for the essay!! thanks 2. Consider using nested loops, then check if guess[i] == answer[j], where the loop indices are named i and j. 3. i tried this and failed
Code:
```        int a=0;
int i;
int j;
for(i=0;i<4;i++)
{
{
a++;
}
for(j=0;j<4;j++)
{
{
a--;
}
}
}
for(i=0;i<4;i++)
{
{
a++;
}
for(j=0;j<4;j++)
{
{
a--;
}
}
}
for(i=0;i<4;i++)
{
{
a++;
}
for(j=0;j<4;j++)
{
{
a--;
}
}
}
for(i=0;i<4;i++)
{
{
a++;
}
for(j=0;j<4;j++)
{
{
a--;
}
}
}
white = a;```
Epic fail lol   Popular pages Recent additions 