my problem solved, thanks to all.
according to matsp and Salem's method, i write two different version codes,
(they are 3d arrays)and they work fine for me , post it, hoping helpful
in the first version , i've a question about free();
version1:
Code:
#include <stdio.h>
#include <stdlib.h>
void fun(int ***arr);
int ***send(void);
int main(void)
{
int ***ptr;
ptr = send();
fun(ptr);
getchar();
return 0;
}
void fun(int ***arr)
{
int i;
for(i=0; i<10; i++)
{
printf("%d\n", arr[0][0][i]); // print just 10 elements
}
free(arr); // should i use free() 3 times as i used 3malloc for arr?
// or 1 free() is enough? }
int ***send(void)
{
int i;
int j;
int k;
int ***twodarray;
for(i=0; i<10; i++)
twodarray = (int***)malloc(10*sizeof(int));
for(i=0; i<10; i++)
twodarray[i] = (int**)malloc(10*sizeof(int));
for(i=0; i<10; i++)
for(j=0; j<10; j++)
twodarray[i][j] = (int*)malloc(10*sizeof(int));
for(i=0; i<10; i++)
for(j=0; j<10; j++)
for(k=0; k<10; k++)
twodarray[i][j][k] = 0;
return twodarray;
}
version2:
Code:
#include <stdio.h>
#include <stdlib.h>
void fun(int (*arr)[10][10]);
int (*send(void))[10][10];
int main(void)
{
int (*ptr)[10][10]; //"this is a pointer to an array of ten elements"
ptr = send(); // ptr[10][10] "10 pointers to integers"
fun(ptr);
getchar();
return 0;
}
void fun(int (*arr)[10][10])
{
int i;
for(i=0; i<10; i++)
{
printf("%d\n", arr[0][0][i]); // print just 10 elements
}
}
int (*send(void))[10][10]
{
int static twodarray[10][10][10] = {0};
return twodarray;
}