Write your question here.
hello everyone, ok so i have an array matrix called tmat,,and i know that in every row of tmax there are values which repeat two times...and am writing a code to extract the values WHICH DOES NOT REPEAT into another matrix called tcopy...the codes compiles fine...and it writes nicely to file...but without the desired result...so is surely me ...can some one check it out and tell me where am doing it wrong? thanks
One last question...how can i get the array tcopy written to file in the form 5x3...and not all the figures in line one after the other? i mean i wish to see the matrix like a matrix on file..not like a list of numbers..thank you again
Code:
 #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++;}
}