This is my first post so please bear with me. I am bringing in 2 files into 2 arrays and then trying co compare the arrays to each other. When I compare the arrays, I am trying to find out how many locations have matching letters in both strings. ) For example:
array1[]={AAACCCGTTT} and array2[]={AACCCCGGTT}; locations 0 and 1 match but location 2 is different) My code seems to work on smaller files but when I open the text files that are over 2,200 characters long I get inconsistancies. The output tells me I have more matches that are possible, but when I test with smaller files it seems to work correctly. I am also trying to use this code /*while ((array1[l] != '\0') && (array2[l] != '\0'))*/ to only read the characters and not the empty part of the array. I have tried using this in my for loop, within another for loop to try to get a count of total characters, in a do-while statement, but it just does not seem to work. Any ideas would be appreciated.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
char array1[20000];
char array2[20000];
char ch;
char compare1;
char compare2;
int match=0;
int nomatch=0;
int i=0;
int j=0;
int counter1=0;
ifstream fin;
ifstream fin2;
fin.open("seq0.txt"); while (fin.get(ch)){
array1[i++] = ch;
array1[i]=0;}
fin2.open("seq1.txt");
while (fin2.get(ch)){
array2[j++] = ch;
array2[j]=0;}
for (int k=0; k<20000; k++){
while (array1[k] != '\0'){
counter1++;}
}
for (int l=0; l<20000; l++){
if (array1[l] = array2[l]){
match++;
}
else {
nomatch++;
}
}
for (int l=0; l<20000; l++) {
compare1 = array1[l];
compare2 = array2[l];
if (compare1 = compare2){
match++;
}
else {
nomatch++;
}
}
cout << match << endl;
cout << nomatch << endl;
fin.close();
return 0;
}