Compare two strings for similar characters

I need to write a piece of code that can compare a "guess" string to an "answer string" and then output how many characters of answers are contained in guess.

this is what i have so far...
1
2
3
4
5
for ( int l = 0 ; l < 4 ; l++ )
            {                                 
                    if ( guess[k] == answer[l] )
                       cCol++;
            } 


the main problem with this is it will return false positives... ex answer = "RPYG" and guess = "YYYY" will return four positive hits when it should only be one....
No, that is correct. The string "RPYG" contains the character 'Y' which would match all four entries in "YYYY". If you are also trying to match the strings based on position then "guess[]" and "answer[]" should use the same offset in their index when you're comparing the chars to eachother.
i already have the code for correct position AND color. i just need to find correct color ONLY. my formula for correct color only would be colorOnly = correctColor - positionAndColor. correctColor is what I am stuck on.... pretty much what i need is how many of the current character are contained in the opposing string. for example answer "RPYG" and guess "YYYY"... I am only concerned about the one y in answer. guess[0] looks at all of string answer and sees a Y in answer[2] then breaks. then... guess[1] realizes it is the same as guess[0] and then begins looking after that first hit
Topic archived. No new replies allowed.