Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/72.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 如何将整数数组传递给库函数_C - Fatal编程技术网

C 如何将整数数组传递给库函数

C 如何将整数数组传递给库函数,c,C,我正试图编写一个程序,调用一个库函数()来解决装箱问题。我从大学起就没学过C,而且我已经很生疏了 我已经把图书馆整理好了。并且静态链接,所以我不会得到关于不存在的函数的错误,但是根据gdb,现在我在binpack3d()函数上得到了一个segfualt。我认为这是某种指针错误。以下是引用库函数的代码: #include <stdio.h> #include "3dbin.h" int main(void) { int w[2]; int h[2]; int d[2]; w[0

我正试图编写一个程序,调用一个库函数()来解决装箱问题。我从大学起就没学过C,而且我已经很生疏了

我已经把图书馆整理好了。并且静态链接,所以我不会得到关于不存在的函数的错误,但是根据gdb,现在我在
binpack3d()
函数上得到了一个segfualt。我认为这是某种指针错误。以下是引用库函数的代码:

#include <stdio.h>
#include "3dbin.h"

int main(void)
{


int w[2];
int h[2];
int d[2];

w[0]=5;
h[0]=6;
d[0]=7;

w[1]=5;
h[1]=6;
d[1]=7;


int x[2];
int y[2];
int z[2];
int bno[1];
int lb;
int ub;

binpack3d(1, 12, 12, 24,
          w, h, d,
         x, y, z, bno,
         lb, ub, 10);


return(1);

}
和头文件(也不确定我是否做对了)

这是它的文档

 * This file contains the callable routine binpack3d with prototype
 *
 *   void binpack3d(int n, int W, int H, int D,
 *          int *w, int *h, int *d, 
 *          int *x, int *y, int *z, int *bno,
 *          int *lb, int *ub, int timelimit);
 *
 * the meaning of the parameters is the following:
 *   n         Size of problem, i.e. number of boxes to be packed.
 *             This value must be smaller than MAXITEMS defined below.
 *   W,H,D     Width, height and depth of every bin.
 *   w,h,d     Integer arrays of length n, where w[j], h[j], d[j]
 *             are the dimensions of box j for j=0,..,n-1.
 *   x,y,z,bno Integer arrays of length n where the solution found
 *             is returned. For each box j=0,..,n-1, the bin number
 *             it is packed into is given by bno[j], and x[j], y[j], z[j] 
 *             are the coordinates of it lower-left-backward corner.
 *   lb        Lower bound on the solution value (returned by the procedure).
 *   ub        Objective value of the solution found, i.e. number of bins
 *             used to pack the n boxes. (returned by the procedure).
 *   timelimit Time limit for solving the problem expressed in seconds.
 *             If set to zero, the algorithm will run until an optimal
 *             solution is found; otherwise it terminates after timelimit
 *             seconds with a heuristic solution. 

我做错了什么?如何调用此函数并显示结果。

您需要找到作为指针的项的地址:

binpack3d(1, 12, 12, 24,
          w, h, d,
         x, y, z, bno,
         &lb, &ub, 10);

看起来你的电话应该在下面。原始代码只传递整数而不是地址(这两个是库函数返回的值)

原型需要更改以反映这两个“返回值”是
int*

void binpack3d(int , int , int , int ,
               int *, int *, int *, 
               int *, int *, int *, int *,
               int *, int *, int );
binpack3d(1, 12, 12, 24,
          w, h, d,
         x, y, z, bno,
         &lb, &ub, 10);
binpack3d(1, 12, 12, 24,
          w, h, d,
         x, y, z, bno,
         &lb, &ub, 10);
void binpack3d(int , int , int , int ,
               int *, int *, int *, 
               int *, int *, int *, int *,
               int *, int *, int );