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 61 62 63 64 65 66 67 68 69 70 71
|
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int R = 5;
const int C = 5;
const int R1 = 5;
const int C1 = 3;
void extract (int mat [R][C]);
void filling (int mat [R1][C1], int value);
int control= 0, st_r = 0, st_c = 0, found = 0;
int rr = 0, cc = 0 ;
int tcopy [5][3];
int main (){
int tmat [5][5] = {{1,2,3,4,4,},
{7,4,5,7,6,},
{4,0,7,9,0,},
{4,5,5,9,0,},
{4,5,9,9,0,},
};
extract(tmat);
fstream file;
file.open("oppose.txt", ios::in | ios::out);
if (file.is_open()){
for(int k= 0; k< 5; k++)
for(int i = 0; i <3; i++)
{file<<tcopy[k][i]<<", ";}
cout<<"copied to file successfully";
file.close();
} else cout<<"cound not open file...";
return 0;
}
void extract (int mat [R][C]){
while (control != R*C)
{
int k = mat [st_r][st_c];
for(int i = 0; i<R ; )
for (int c= 0; c<C; c++)
{
{ if (k == mat [i][c]); //over here i want to loop over the whole row.
found++;}// is it one at a time? or am looping the row?
if (found < 2) {filling(tcopy,k );}
found = 0;
if(st_c < C) st_c++;
else{ st_c = 0;
if(st_r < R) st_r ++;} i++;
}
control ++;
}
}
void filling (int mat [R1][C1], int value)
{
mat[rr][cc] = value;
if (cc < C1) cc++;
else { cc = 0;
if(rr<R1) rr++;}
}
|