I'm trying to create a program in C++ that could be able to diff two .txt files.
struct line
{
string text;
size_t num;
int status;
};
void compareFiles(vector<line> &buffer_1, vector<line> &buffer_2, size_t index_1, size_t index_2)
{
while(index_1 < buffer_1.size())
{
while(index_2 < buffer_2.size())
{
X = buffer_1[index_1].text;
Y = buffer_2[index_2].text;
if(X == Y)
{
++index_1;
++index_2;
}
else
{
LCS();
string lcs = printLCS(X.length(), Y.length());
/*
* Here's my problem
*/
}
}
}
}
As you can see, I have two buffers (vectors of lines) previously loaded with files contents . I also have the LCS algorithm fully functional (tested). LCS works on strings X and Y globally defined.
So, what I really need to do is compare buffers line by line with LCS, but I didn't manage a way to do it.
Could you please help me?
while()loops -- what happens when you run out of lines inbuffer_2?index_1will never be incremented, and the outermostwhileloop will never terminate.while (index_1 < buffer_1.size() || index_2 < buffer_2.size()) { ... }would allow you to run over both inputs entirely. (Maybe one input differs from the other by only one new line appended at the end...)