Find unique rows in a matrix

Tag: file , matrix , unique , rows Author: lqazsxdcfvgbhnjm Date: 2014-04-05

I have a matrix with me in a file and I need to find the unique rows, i.e. I have to pick a row that doesn't repeat or if it repeats, I have to take only one of the several repetitions and form a new matrix. I have a 9801x25 matrix in a file. I don't know how to upload the file here, so I just copied a sample in http://codepad.org/fkPWvFIS

My approach to the problem: I have taken an array arr[9801][26] where arr[][25] is a flag to that row, if a row was found to be repeated, the flag is incremented by 1. This is done for all reps except the first one encountered. Since initially all the flags were assigned zero, I can count the number of unique rows. The answer however is 9183 and I keep getting 8885. My question is where is my logic going wrong? Suggest me a way to upload a file and you can get more clarity on the question. Thanks in advance.

for(i=0;i<9801;i++)
{
    for(j=0;j<25;j++)
    {
        fscanf(ft,"%d",&arr[i][j]);
    }
    arr[i][25]=0;
}
for(i=0;i<9801;i++)
{
    for(j=i+1;j<9801;j++)
    {
        for(k=0;k<25;k++)
        {
            if(arr[i][k]==arr[j][k])
            {
                cntr++;
            }
        }
        if(cntr==25)
           {
             arr[i][25]++;
           }
        cntr=0;
    }
}
cntr=0;
k=0;
for(i=0;i<9801;i++)
{
    if(arr[i][25]==0)
        {
            cntr++;
            for(j=0;j<25;j++)
                printf("%d ",arr[i][j]);
            printf("\n");
        }
    else
        {
            printf("%d\n",i);
            k++;
        }
}