LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with char 3D Array... C-Guru wanted !

/*
Hi,
I would like to define a 3D char Array global.But I dont want to define the Array static,
the Array Size should be defined through a function.

How can I do it ? Please help..

For a code example, I would be really happy.Thanks a lot !!!
*/
//So I dont want it anymore :

#include

#define x 10
#define y 10
#define z 10

static char Data[x][y][z];//static declaration

void Print(void);


void main (void){

strcpy(Data[0][2],"Hello");
Print();

}

void Print (void)
{
printf("%s\n",Data[0][2]);
}

/* Dont work... : (

#include

static int *Data;

void Print(void);
int Define(int,int,int);


void main (void){

Data = Define(10,10,10);
strcpy(*Data[0][2
],"Hello");
Print();

}

void Print (void)
{
printf("%s\n",*Data[0][2]);
}

int Define (int x,int y,int z)
{
static char Array[x][y][z];
return &Array[0][0][0];
}

*/
0 Kudos
Message 1 of 3
(3,031 Views)
/* in ANSI C, you may do as follows */

#include "alloc.h"

char ***Data;

void allocate(int x,int y,int z);

void allocate(int x,int y,int z)
{
int i,j;
Data=(char ***)malloc(x*sizeof(char **));
for(i=0;i Data[i]=(char **)malloc(y*sizeof(char *));
for(j=0;j Data[i][j]=(char *)malloc(z*sizeof(char));
}
}
}

/* I have not tested it yet though. */
0 Kudos
Message 2 of 3
(3,031 Views)
thanks!
0 Kudos
Message 3 of 3
(3,031 Views)