how to use the str parameter

I need to compare a string array with a master string and get the total of correct match in every string.
for example:
master string: ABABBBBBABBAAA
string a: AAABBB BABBAAA;
string b: ABABBBBBABBBB;
string c: ABABBBBBABBAAA;

output string a: 10 correct
output string b: 11 correct
output string c: 14 correct


I am thinking to use the "str" parameters but i am not sure how to used. any hint or example.
thanks.

You could loop through the three strings, which can also be thought of as character arrays.

Then compare each element individually to the master string and increment a variable to keep track of the number of correct in string a, b, and c.

maybe have it something like

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

#include <iostream>
#include<string>


int main()
{
    char Master_String[]="ABABBBBBABBAAA";
    char String_A[]="AAABBB BABBAAA";
    char String_B[]="ABABBBBBABBBB";
    char String_C[]="ABABBBBBABBAAA";
    int a = 0, b = 0, c = 0;

    for (int i = 0;i < 14;i++){
            if (String_A[i] == Master_String[i]){
                a++;}
    }

    for (int i = 0;i < 14;i++){
            if (String_B[i] == Master_String[i]){
                b++;}
    }

    for (int i = 0;i < 14;i++){
            if (String_C[i] == Master_String[i]){
                c++;}
    }

    std::cout << "Output String A: " << a << " correct.\n";
    std::cout << "Output String B: " << b << " correct.\n";
    std::cout << "Output String C: " << c << " correct.\n";
	return 0;
}


Last edited on
Thanks. If I read this string from an array how I suppose to compare ?
Last edited on
Topic archived. No new replies allowed.