I'm writing yet another function that would determine how many characters in the first string must be changed to change the first string into the second. I'll provide a short example...
string1 = GHRIRMMRIEOFBB
string2 = GHRIKKRLIEAFBBTOOLS
int difference (const Protein Datalist[]) {
int numLoops = 0;
char ch1, ch2;
string s1, s2, ss;
int diff = 0, size1, size2;
s1 = Datalist[0].Sequence;
s2 = Datalist[2].Sequence;
size1 = s1.length();
size2 = s2.length();
if (s1 < s2)
ss = s2;
if (s1 > s2)
ss = s1;
for (numLoops = 0; numLoops < ss.length(); numLoops++) {
ch1 = s1.at(numLoops);
ch2 = s2.at(numLoops);
if (ch1 != ch2)
diff++;
numLoops++;
}
return (diff);
}
I believe I'm almost there but for some reason this code doesn't give me the right number. SS takes the larger of the 2 strings and loops it that many times. Any suggestions? Thanks for the help.
Good call on the extra numLoops but I added "s2.resize(size1)" under the 2nd if statement and "s1.resize(size2)" under the 1st if statement and I'm not getting the right number still. I think it's getting everything correct except for the extra characters that s2 has.
for some reason when I use resize it's telling me "2 overloads have no legal conversion for 'this' pointer". resize worked fine when I had Datalist as my parameter but I have since changed passed the 2 strings needed directly to the function and now resize doesn't work.