hello,
I have some problem with my project in C. I want do define a generic type of matrix. with this type I can save any kind of type(int, double, float...). but I have some errors in my code. if someone can help me I'll be very gratefull. the code is:
the errors is :
error C2036: 'void *' : unknown size
error C2120: 'void' illegal with all types
error C2036: 'void *' : unknown size
error C2069: cast of 'void' term to non-'void'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
thanks to all,
mos
I have some problem with my project in C. I want do define a generic type of matrix. with this type I can save any kind of type(int, double, float...). but I have some errors in my code. if someone can help me I'll be very gratefull. the code is:
Code:
typedef struct arr{
void * p_arr;
}arr;
typedef struct matrix{
arr * p_mat;
char* name;
int size_h;
int size_w;
int type;
}matrix;
matrix matrix_zeroes(int i,int j) //returen pointer to matrix (ixj)
{
int n=0,m=0;
matrix mat;
mat.size_h=i;
mat.size_w=j;
mat.name="matrix_zeroes";
mat.p_mat = (arr*)(malloc(i*sizeof(arr)));
for(n=0;n<i;n++)
(int*)mat.p_mat[n].p_arr=(int*)(malloc(j*sizeof(int)));
for(n=0;n<i;n++)
for(m=0;m<j;m++)
mat.p_mat[n].p_arr[m]=0;
return mat;
}
void matrix_print(matrix mat)
{
int m,n;
int i=mat.size_h,j=mat.size_w;
for(n=0;n<i;n++)
{
for(m=0;m<j;m++)
printf(" %d ",(int)(mat.p_mat[n].p_arr[m]));
printf("\n");
}
}
the errors is :
error C2036: 'void *' : unknown size
error C2120: 'void' illegal with all types
error C2036: 'void *' : unknown size
error C2069: cast of 'void' term to non-'void'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
thanks to all,
mos
Comment