Hi, I've been trying to dynamically dimension a multidimensional array using C but I keep getting a compiler error. I've tried going through the help files example, but theres didn't work. Thanks for any help
PHP Code:#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int rows=3,columns=5;
void main(void)
{
float *matrix=NULL;
int i,j;
matrix = (float*)calloc(rows, sizeof(float*));
for (i=0; i<rows; ++i)
{
matrix[i] =(float*)calloc(columns,sizeof(float*));
}
for (i=0; i<rows; i++)
{
for (j=0; j<columns; j++)
{
//matrix[i][j] = i+j;
}
}
for (i=0; i<rows; ++i)
{
printf("\n\n");
for (j=0; j<columns; ++j)
{
printf("%5.2Lf", matrix[i]);
}
}
for (i=0; i<rows; i++)
{
//free(matrix[i]);
}
free(matrix);
getch();
}




Reply With Quote