Grazie per il consiglio credo di aver applicato l idea tuttavia non capisco perchè non funzioni il contatore

codice:
 struct salva_elementi
{
    int counter;
    int counter2;
} struttura;

typedef struct indic1
{
    int primoi;
    struct indicei *next;
} indicei;

typedef struct indic2
{
    int primoj;
    struct indicej *next;
} indicej;

indicei *trova_indicii(indicei **p, int i)
{
    indicei *a = (indicei*) malloc(sizeof(indicei));
    a->next = *p;
    *p = a;
    a->primoi= i;
    return a;
}
indicej *trova_indicij(indicej **p, int j)
{
    indicej *a = (indicej*) malloc(sizeof(indicej));
    a->next = *p;
    *p = a;
    a->primoj= j;
    return a;
}

indicei **scorrilistai(indicei **n, int i)
{
    while (*n != NULL)
    {
        if ((*n)->primoi==i)
        {
            return n;
        }
        n= &(*n) ->next;
    }
    return NULL;
}

indicej **scorrilistaj(indicej **n, int j)
{
    while (*n != NULL)
    {
        if ((*n)->primoj==j)
        {
            return n;
        }
        n= &(*n) ->next;
    }
    return NULL;
}

int cerca_elementiovest (int x, int i, int j, int matrice[15][10],int c1, int c2)
{

    int l,k=0;
    indicei *p=NULL;
    indicej *q=NULL;
    indicei(&p,i);
    indicej(&q,j);
    k=scorrilistai(&p,i);
    l=k=scorrilistai(&q,i);
    if(x==matrice[i][j-1] && k!=i && l!=1)
    {
        struttura.counter=struttura.counter+1;;
    }
}

int cerca_elementiest (int x, int i, int j, int matrice[15][10],int c1, int c2)
{
    int l,k=0;
    indicei *p=NULL;
    indicej *q=NULL;
    indicei(&p,i);
    indicej(&q,j);
    k=scorrilistai(&p,i);
    l=k=scorrilistai(&q,i);
    if(x==matrice[i][j+1] && k!=i && l!=1)
    {
        struttura.counter=struttura.counter+1;
    }
}
int cerca_elementinord (int x, int i, int j, int matrice[15][10],int c1, int c2)
{
    int l,k=0;
    indicei *p=NULL;
    indicej *q=NULL;
    indicei(&p,i);
    indicej(&q,j);
    k=scorrilistai(&p,i);
    l=k=scorrilistai(&q,i);
    if(x==matrice[i-1][j] && k!=i && l!=1)
    {
        struttura.counter=struttura.counter+1;
    }
}

int cerca_elementisud (int x, int i, int j, int matrice[15][10],int c1, int c2)
{
    int l,k=0;
    indicei *p=NULL;
    indicej *q=NULL;
    indicei(&p,i);
    indicej(&q,j);
    k=scorrilistai(&p,i);
    l=k=scorrilistai(&q,i);
    if(x==matrice[i+1][j] && k!=i && l!=1 )
    {
        struttura.counter=struttura.counter+1;
    }
}

int repeat (int matrice[15][10])
{
    int i,j,x,k=0;
    int c1=0, c2=0;
    for(i=0; i<15; i++)
    {
        for(j=0; j<10; j++)
        {
            x=matrice[i][j];
            if(j!=0 && x!=0)
            {
                cerca_elementiovest(x,i,j,matrice,c1,c2);
            }
            if(j!=9 && x!=0)
            {
                cerca_elementiest(x,i,j,matrice,c1,c2);
            }
            if(i!=0 && x!=0)
            {
                cerca_elementinord(x,i,j,matrice,c1,c2);
            }
            if(i!=14 && x!=0)
            {
                cerca_elementisud(x,i,j,matrice,c1,c2);
            }

            if(j!=0 && j!=9 && i!=0 && i!=14 && x!=matrice[i+1][j] && x!=matrice[i-1][j] && x!=matrice[i][j-1] && x!=matrice[i][j+1])
            {
                c2=struttura.counter;
                struttura.counter=0;
            }
            if(j==0 && i!=0 && i!=14 && x!=matrice[i][j+1] && x!=matrice[i+1][j] && x!=matrice[i][j-1])
            {
                c2=struttura.counter;
                struttura.counter=0;
            }
            if(j==9 && i!=0 && i!=14 && x!=matrice[i+1][j] && x!=matrice[i-1][j] && x!=matrice[i][j-1])
            {
                c2=struttura.counter;
                struttura.counter=0;
            }
            if(i==0 && j!=0 && j!=9 && x!=matrice[i+1][j] && x!=matrice[i][j+1] && x!=matrice[i][j-1])
            {
                c2=struttura.counter;
                struttura.counter=0;
            }
            if(i==14 && j!=0 && j!=9 && x!=matrice[i+1][j] && x!=matrice[i][j+1] && x!=matrice[i][j-1])
            {
                c2=struttura.counter;
                struttura.counter=0;
            }
            if(i==0 && j==0 && x!=matrice[i][j+1] && x!=matrice[i-1][j])
            {
                c2=struttura.counter;
                struttura.counter=0;
            }
            if(i==0 && j==9 && x!=matrice[i+1][j] && x!=matrice[i][j-1])
            {
                c2=struttura.counter;
                struttura.counter=0;
            }
            if(j==0 && i==14 && x!=matrice[i][j+1] && x!=matrice[i-1][j] )
            {
                c2=struttura.counter;
                struttura.counter=0;
            }
            if(j==9 && i==14 && x!=matrice[i-1][j] && x!=matrice[i][j-1] )
            {
                c2=struttura.counter;
                struttura.counter=0;
            }
        }
    }
    printf("%d \n \n %d \n ", k,struttura.counter);
}