peppedilillo
05-05-2012, 01:31
#include <stdio.h>
#include <stdlib.h>
int** alloca(int,int);
main()
{
int **mat,i,j;
mat=alloca(2,2);
for(i=0;i<2;++i)
{
for(j=0;j<2;++j)
mat[i][j]=0;
}
}
int** alloca(int r,int c)
{
int **matrix,i;
matrix = (int**)malloc(r*sizeof(int*));
for (i=0; i<r; i++)
matrix[i] = (int*)malloc(c*sizeof(int));
return matrix;
}
ciao ragazzi!
sto provando a scrivere una funzione che allochi dinamicamente una matrice di n righe ed m colonne.
compilando ottengo gli errori:
test2.c:6:21: error: macro "alloca" passed 2 arguments, but takes just 1
test2.c:6: error: ‘alloca’ redeclared as different kind of symbol
test2.c:15:16: error: macro "alloca" passed 2 arguments, but takes just 1
test2.c:26:25: error: macro "alloca" passed 2 arguments, but takes just 1
test2.c:27: error: syntax error before ‘{’ token
test2.c:30: error: ‘r’ undeclared here (not in a function)
test2.c:30: warning: initialization makes integer from pointer without a cast
test2.c:30: error: initializer element is not constant
test2.c:30: warning: data definition has no type or storage class
test2.c:31: error: syntax error before ‘for’
la linea 6 è quella relativa la dichiarazione della funzione alloca
int** alloca(int,int);
Qualcuno riesce ad aiutarmi? : - (
#include <stdlib.h>
int** alloca(int,int);
main()
{
int **mat,i,j;
mat=alloca(2,2);
for(i=0;i<2;++i)
{
for(j=0;j<2;++j)
mat[i][j]=0;
}
}
int** alloca(int r,int c)
{
int **matrix,i;
matrix = (int**)malloc(r*sizeof(int*));
for (i=0; i<r; i++)
matrix[i] = (int*)malloc(c*sizeof(int));
return matrix;
}
ciao ragazzi!
sto provando a scrivere una funzione che allochi dinamicamente una matrice di n righe ed m colonne.
compilando ottengo gli errori:
test2.c:6:21: error: macro "alloca" passed 2 arguments, but takes just 1
test2.c:6: error: ‘alloca’ redeclared as different kind of symbol
test2.c:15:16: error: macro "alloca" passed 2 arguments, but takes just 1
test2.c:26:25: error: macro "alloca" passed 2 arguments, but takes just 1
test2.c:27: error: syntax error before ‘{’ token
test2.c:30: error: ‘r’ undeclared here (not in a function)
test2.c:30: warning: initialization makes integer from pointer without a cast
test2.c:30: error: initializer element is not constant
test2.c:30: warning: data definition has no type or storage class
test2.c:31: error: syntax error before ‘for’
la linea 6 è quella relativa la dichiarazione della funzione alloca
int** alloca(int,int);
Qualcuno riesce ad aiutarmi? : - (