ginochan
11-05-2009, 19:03
Ciao, sto scrivendo un programmino per la creazione e gestione di matrici realizzate con liste di liste.
Finora ho scritto questo codice:
#include <malloc.h>
#include <stdio.h>
typedef struct Colonne
{
int data;
struct Colonne *next;
} Colonne;
typedef struct Matrice
{
struct Colonne *col;
struct Matrice *next;
} Matrice;
void LeggiMatrice(Matrice *mat, int N, int M)
{
struct Matrice *y;
struct Colonne *temp;
int i,j;
for(i=0;i<N;i++)
{
y=mat;
for(j=0;j<M;j++)
{
if((M>1)&&(mat->next==NULL))
{
mat->next=(struct Matrice *)malloc(sizeof(struct Matrice));
}
if(y->col==NULL)
{
y->col=(struct Colonne *)malloc(sizeof(struct Colonne));
temp=y->col;
printf("\n Inserisci l'elemento in posizione %d %d :",i,j);
scanf("%d", & temp->data);
}
else
{
while(temp->next=NULL){temp=temp->next;}
temp->next=(struct Colonne *)malloc(sizeof(struct Colonne));
temp=temp->next;
printf("\n Inserisci l'elemento in posizione %d %d :",i,j);
scanf("%d", & temp->data);
}
y=y->next;
}
}
}
void StampaColonne (Matrice *mat)
{
struct Matrice *c;
struct Colonne *r;
c= mat->next;
r= mat->col;
while(c->next==NULL)
{
printf("\n");
while(r->next==NULL)
{
printf(" %d ",r->data);
r=r->next;
}
c=c->next;
}
}
int main()
{
int n,m;
struct Matrice *mt;
mt=(struct Matrice *)malloc(sizeof(struct Matrice));
printf("\n Numero di righe: ");
scanf("%d",&n);
printf("\n Numero di colonne: ");
scanf("%d",&m);
LeggiMatrice(&mt,n,m);
StampaColonne(mt);
system("pause");
}
Quando vado a compilare mi dice: "[Warning] passing arg 1 of `LeggiMatrice' from incompatible pointer type"
e da qui presuppongo che ci sia un problema con il passaggio dei valori alla finzione leggi matrice. Non riesco però a risolverlo... qualcuno mi sa aiutare?
grazie
Finora ho scritto questo codice:
#include <malloc.h>
#include <stdio.h>
typedef struct Colonne
{
int data;
struct Colonne *next;
} Colonne;
typedef struct Matrice
{
struct Colonne *col;
struct Matrice *next;
} Matrice;
void LeggiMatrice(Matrice *mat, int N, int M)
{
struct Matrice *y;
struct Colonne *temp;
int i,j;
for(i=0;i<N;i++)
{
y=mat;
for(j=0;j<M;j++)
{
if((M>1)&&(mat->next==NULL))
{
mat->next=(struct Matrice *)malloc(sizeof(struct Matrice));
}
if(y->col==NULL)
{
y->col=(struct Colonne *)malloc(sizeof(struct Colonne));
temp=y->col;
printf("\n Inserisci l'elemento in posizione %d %d :",i,j);
scanf("%d", & temp->data);
}
else
{
while(temp->next=NULL){temp=temp->next;}
temp->next=(struct Colonne *)malloc(sizeof(struct Colonne));
temp=temp->next;
printf("\n Inserisci l'elemento in posizione %d %d :",i,j);
scanf("%d", & temp->data);
}
y=y->next;
}
}
}
void StampaColonne (Matrice *mat)
{
struct Matrice *c;
struct Colonne *r;
c= mat->next;
r= mat->col;
while(c->next==NULL)
{
printf("\n");
while(r->next==NULL)
{
printf(" %d ",r->data);
r=r->next;
}
c=c->next;
}
}
int main()
{
int n,m;
struct Matrice *mt;
mt=(struct Matrice *)malloc(sizeof(struct Matrice));
printf("\n Numero di righe: ");
scanf("%d",&n);
printf("\n Numero di colonne: ");
scanf("%d",&m);
LeggiMatrice(&mt,n,m);
StampaColonne(mt);
system("pause");
}
Quando vado a compilare mi dice: "[Warning] passing arg 1 of `LeggiMatrice' from incompatible pointer type"
e da qui presuppongo che ci sia un problema con il passaggio dei valori alla finzione leggi matrice. Non riesco però a risolverlo... qualcuno mi sa aiutare?
grazie