私は、ユーザ入力として取られた3D座標点の26の近傍ボクセルを生成するために以下のコードを書いた。私は隣接するボクセルの座標値を生成するが、以下のエラーと警告を得る関数nbr26を使用した。関数を介して2D配列に値を格納する
plane.c: In function ‘nbr26’:
plane.c:28:18: error: **expected expression before ‘{’ token**
Arr[26][3] = {{p0-1,q0,r0},{p0+1,q0,r0},{p0,q0-1,r0},{p0,q0+1,r0},{p0,q0,r0-1},{p0,q0,r0+1},{p0-1,q0-1,r0},{p0+1,q0-1,r0},{p0-1,q0+1,r0},{p0+1,q0+1,r0},{p0-1,q0,r0-1},{p0+1,q0,r0-1},{p0-1,q0,r0+1},{p0+1,q0,r0+1},{p0,q0-1,r0-1},{p0,q0-1,r0+1},{p0,q0+1,r0-1},{p0,q0+1,r0+1},{p0-1,q0-1,r0-1},{p0-1,q0-1,r0+1},{p0-1,q0+1,r0-1},{p0-1,q0+1,r0+1},{p0+1,q0-1,r0-1},{p0+1,q0-1,r0+1},{p0+1,q0+1,r0-1},{p0+1,q0+1,r0+1}};
^
plane.c:29:5: warning: **return from incompatible pointer type** [enabled by default]
return Arr;
^
問題を少し見せてください!
#include<stdio.h>
#include<stdlib.h>
int** nbr26(int, int, int, int[][3]);
int main()
{
int x0, y0, z0, a, b, c, d, Ar[26][3];
printf("\nPlease enter a point on the plane : ");
scanf("%d %d %d", &x0, &y0, &z0);
printf("\nPlease enter a norm of the plane : ");
scanf("%d %d %d", &a, &b, &c);
printf("\nUser Input");
printf("\n(%d,%d,%d)", x0, y0, z0);
printf("\t<%d,%d,%d>", a, b, c);
d = -a*x0-b*y0-c*z0;
printf("\nScaler Equation of the given plane is : %dx+%dy+%dz+ (%d)=0", a, b, c, d);
int** ra = nbr26(x0,y0,z0,Ar);
printf("\n26 neighbours of the given point are : ");
printf("(%d,%d,%d)\n",x0-1,y0-1,z0-1);
return 0;
}
int** nbr26(int p0, int q0, int r0, int Arr[26][3])
{
Arr[26][3] = {{p0-1,q0,r0},{p0+1,q0,r0},{p0,q0-1,r0},{p0,q0+1,r0}, {p0,q0,r0-1},{p0,q0,r0+1},{p0-1,q0-1,r0},{p0+1,q0-1,r0},{p0-1,q0+1,r0},{p0+1,q0+1,r0},{p0-1,q0,r0-1},{p0+1,q0,r0-1},{p0-1,q0,r0+1},{p0+1,q0,r0+1},{p0,q0-1,r0-1},{p0,q0-1,r0+1},{p0,q0+1,r0-1},{p0,q0+1,r0+1},{p0-1,q0-1,r0-1},{p0-1,q0-1,r0+1},{p0-1,q0+1,r0-1},{p0-1,q0+1,r0+1},{p0+1,q0-1,r0-1},{p0+1,q0-1,r0+1},{p0+1,q0+1,r0-1},{p0+1,q0+1,r0+1}};
return Arr;
}
を行うことを余儀なくされているあなたはそれを行うことはできません。そのように宣言した場合にのみ、配列を初期化することができます。 [memcpy](http://www.tutorialspoint.com/c_standard_library/c_function_memcpy.htm)や他の技術を使って、 – LPs
...という仕事をすることができます.2次元配列ではポインタのポインタではありません。 – LPs