|
-
Nov 25th, 2002, 06:06 PM
#1
Thread Starter
Lively Member
multi dimensional arrays using C
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();
}
-
Nov 25th, 2002, 06:28 PM
#2
Search this forum. It doesn't work this way and workarounds have been presented.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|