Studio leggendo e compilando codici da questo ottimo forum.
Questo programma che dovrebbe essere corretto e funzionante >>>
http://forum.html.it/forum/showthrea...hlight=matrice
a me da >>>
../vedere.c:48: error: conflicting types for ‘Alloca’
../vedere.c:12: error: previous declaration of ‘Alloca’ was here
../vedere.c: In function ‘Alloca’:
../vedere.c:50: warning: incompatible implicit declaration of built-in function ‘calloc’
PS >> per comodità metto il codice in questione >>
codice:
#include <stdio.h>
#include <time.h>
#include <math.h>
typedef struct {
int **m;
int r;
int c;
} mat;
void Alloca(mat);
main () {
int i,j;
mat M;
M.r=5;
M.c=6;
Alloca(M);
srand(time(NULL));
for (i=0,j=0;i<M.r;j++) {
if (j==M.c) {
j=0;
i++;
}
M.m[i][j]= rand()%20;
}
for (i=0,j=0;i<M.r;j++) {
if (j==M.c) {
j=0;
i++;
printf("\n");
}
printf("%d\t", M.m[i][j]);
}
}
.. void Alloca (mat *M) {
int i;
(*M).m=(int**)calloc((*M).r,sizeof(int*));
for (i=0;i<(*M).r;i++)
(*M).m[i]=(int*)calloc((*M).c,sizeof(int));
return;
}