I'm writing a program that reads two files and compares them. One file holds chunks of strings that are to be matched to places in the other, big file. Up till now most of what I got is quasi code. It goes like this:
int main()
{
//Read reference file exit if trouble
ifstream refFile("test_reference.txt"); //some 100Mb
if(!refFile)
{
cerr << "Error : Reference file could not be opened." << endl;
exit(1);
} else {
//If refFile could be opened, read search file, exit if trouble.
ifstream sFile("test_part.txt");
if(!sFile)
{
cerr << "Error : Search file could not be opened." << endl;
exit(1);
}
}
while(refFile.is_open()){
while(sFile.is_open()){
//Buffer entire refFile
//read sFile line by line.
//
if(/* compare string (one line) in sFile with refFile */){
//return place where hit, exit. Next line in search file.
} else {
reverse string
}
if(/* compare reversed string (one line) in sFile with refFile */){
//return place where hit, negative to part from unreversed, exit. Next line in search file.
} else {
return 0; //No hit
}
}
}
I'm helping my girlfriend with some genome stuff. (Shes a post doc in biology.) I like to do this hasty, but I don't know how to manipulate, compare strings read from file in c++. Specially the part where I written buffer files, but any help is appreciated! :-)