hai guys...
i'm facing a problem on how to compare and then combine back the two different files (text files)
i have 2 text files which i stored them in 2D array
this is my first text files. I named this file as text 1
0 1 2
1 2 3
3 2 1
3 1 1 1
3 1 1 1
3 1 1 1
and here is my text files number 2
1 2 3
3 2 1
what I plan to do is to compare this 2 files .
If the numbers in text 1 exist in text 2, then the number below in text 1 will be change to 4
for example :
In text 1, there is 0 1 2 , but in text 2, 0 1 2 doesn't exist , so 3 is remained and display
next, in text 1, there is 1 2 3,and in text 2, 1 2 3, exist, therefore 3 in bold will be turned to 4 and display
The output should be like this :
0 1 2
1 2 3
3 2 1
3 1 1 1
4 1 1 1
4 1 1 1
And same to others
I have tried many times to code this. But I cannot got as I want.
I hope anyone here can help me.
tqvm..
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include<iostream>
#include<fstream>
using namespace std;
void main()
{
int no1,no3,**m,**n,**t,dummy;
ifstream infile1;
infile1.open(text1.txt);
ifstream infile2;
infile2.open("text2.txt");
infile1 >> no1;
infile1 >> no1 ;
infile2 >> no3;
m = new int *[no1];
for(int i=0;i<no1;i++)
m[i] = new int[3];
n = new int *[no1];
for(int i=0;i<no1;i++)
n[i] = new int[3];
t = new int *[no3];
for(int i=0;i<no3;i++)
t[i] = new int[3];
for(int i=0;i<no1;i++)
{
infile1 >> m[i][0] >> m[i][1] >> m[i][2]
infile1 >> dummy >> n[i][0] >> n[i][1] >> n[i][2];
}
for(int j=0;j<no3;j++)
infile2 >> t[i][0] >> t[i][1] >> t[i][2];
for(int i=0;i<no1;i++)
{
for(int j=0;j<no3;j++)
{
if(m[i][0] == t[j][0] && m[i][1] == t[j][1] && m[i][2] == t[j][2])
{
dummy = 4;
cout << dummy << endl;
}
else
{
dummy =3;
cout << dummy << endl;
}
}
}
}
|
This is my code, and I hope anyone here can help me by let me know, what is wrong with my code...
tqvm again ... pliss~~