Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C-传递3d阵列、分配和填充_C_Arrays - Fatal编程技术网

C-传递3d阵列、分配和填充

C-传递3d阵列、分配和填充,c,arrays,C,Arrays,假设我在下面有一个函数 void function createBands(boolean option) { int i, j; int ***bands = (int ***)malloc((SIZE + 1) * sizeof(int **)); for (i = 0; i < SIZE; i++) { bands[i] = (int **)malloc(HEIGHT * sizeof(int *)); for (j = 0; j < HEIGHT;

假设我在下面有一个函数

void function createBands(boolean option) {
  int i, j;
  int ***bands = (int ***)malloc((SIZE + 1) * sizeof(int **));
  for (i = 0; i < SIZE; i++) {
    bands[i] = (int **)malloc(HEIGHT * sizeof(int *));
    for (j = 0; j < HEIGHT; j++)
      bands[i][j] = (int *)malloc(WIDTH * sizeof(int));
  }
  iterator *it =
      createIterator(params); // do not be confused it is a structure with
                              // methods andaeribute just like Iterator class in
                              // java . Methods are poniters to functions.
  repare_array(bands[Size], it);
}
void prepare_array(int **band, iterator *it) { read_array(band, it); }

read_array(int **band, iterator *it) {
  for (int i = 0; i < Height; i++)
    band[i] = (int *)it->next();
}

// Now in Iterator.c  I have the iterator structure with the methods etc I will
// write just some line form iterator.

void *next() {
  byte *b =
      a function that reads bytes form a file and returns byte * CORECTLY !!!;
  return b == NULL ? NULL : bytetoT(b);
  // this function make void form byte conversion but it doesnt work so I make
  // only a cast in read_aray as you see. SUppose just return b wich is byte(i
  // know in C isn't any byte but I redeclared all the types to be JAVA.)
}
void函数createBands(布尔选项){
int i,j;
int***波段=(int***)malloc((尺寸+1)*sizeof(int**));
对于(i=0;inext();
}
//现在在Iterator.c中,我有了迭代器结构和我将要介绍的方法等
//写一些行形式的迭代器。
void*next(){
字节*b=
从文件中读取字节并返回byte*CORECTLY!!!;
返回b==NULL?NULL:bytetoT(b);
//这个函数可以进行无效形式的字节转换,但它不起作用,所以我
//如您所见,只有一个cast-in-read_-aray。假设只返回b,其中b是字节(i)
//C中的know不是任何字节,但我将所有类型重新声明为JAVA。)
}
问题是我应该在哪里分配频带,因为在这种情况下,函数返回的1D向量是可以的,因为我看到函数范围中的值。但当它返回数组[i]时,我得到了一个未分配的3dVector。 我需要用数据表b接收带[size][I][j]。在b中,数据是好的,然后我得到了空带。 到目前为止,我在调用read_array之前在prepare aray中进行了另一次分配,在那里我分配了**波段,然后我得到了一些结果,但我没有信心。 抱歉搞混了!每一条评论都对我有好处。也许我所做的是好的,我不知道!。 我对C并不陌生,我只是在很长一段时间内不使用指针。

如果它是2D指针(**),你必须用2D数组的地址分配它,如果它是1D数组,你必须用1D数组的地址分配它

用于读取数组函数

             read_array(int**array...)
              {
               for(i=0;i<HEIGHT(the same as in allocation);i++)
                  `enter code here`array[i] = function();//function return an 1D array 
              }
读取数组(int**array…)
{

对于(i=0;我在很多级别上都很难理解…你没有一个3D数组,你有一个指向指针的指针。还有,你到底想完成什么?还有,你不应该强制执行
malloc()
的返回。什么是
sizeofint
?我有一个我想要压缩的3D图像。我有一个从图像(字节)读取1D数组的函数然后我将字节转换为int,我试图感受一个代表图像的数组。我有一个函数,用于分配malloc和void,然后我进行转换。为了更好地理解,我编写了malloc函数。问题是3dArray没有分配。函数()有反签名:void*function()。我有array[I]=(int*)function();我还没有解决问题。我所做的是在read_数组中重新分配数组,但我不知道这是否正常,因为我在第一个函数中分配了一次数组,然后在第二个函数中再次分配了数组。