新手有问题想请教,一段比较简单的代码
我不知道我输出的数组为什么一直错int main(int argc, char *argv[])
{
void SIZEINPUT(int nbounds, char* bndnames, double* boundarycoeffs);
int nbounds = 3;
char* bndnames[] = { "line_x","line_xy_1","line_xy_1" };
double coeffs[9];
int j;
SIZEINPUT(nbounds, bndnames, coeffs);
for (j = 0; j < 9; j++) {printf("\n %f \n", coeffs[j]);
}
}
void SIZEINPUT(int nbounds, char* bndnames, double* boundarycoeffs)
{
int i;
double radius1 = 0.2;
double radius2 = 0.45;
double radius3 = 0.46;
double radius4 = 0.5;
double radius5 = 0.8;
double hwidth = 0.8;
for (i = 0; i<nbounds; i++) {
if (bndnames[i] == "circle_1")
{
boundarycoeffs[i * 3] = 0.0;
boundarycoeffs[i * 3 + 1] = 0.0;
boundarycoeffs[i * 3 + 2] = radius1;
}
else if (bndnames[i] == "circle_2")
{
boundarycoeffs[i * 3] = 0.0;
boundarycoeffs[i * 3 + 1] = 0.0;
boundarycoeffs[i * 3 + 2] = radius2;
}
else if (bndnames[i] == "circle_3")
{
boundarycoeffs[i * 3] = 0.0;
boundarycoeffs[i * 3 + 1] = 0.0;
boundarycoeffs[i * 3 + 2] = radius3;
}
else if (bndnames[i] == "circle_4")
{
boundarycoeffs[i * 3] = 0.0;
boundarycoeffs[i * 3 + 1] = 0.0;
boundarycoeffs[i * 3 + 2] = radius4;
}
else if (bndnames[i] == "circle_5")
{
boundarycoeffs[i] = 0.0;
boundarycoeffs[i + 1] = 0.0;
boundarycoeffs[i + 2] = radius5;
}
else if (bndnames[i] == "line_x")
{
boundarycoeffs[i * 3] = 1.0;
boundarycoeffs[i * 3 + 1] = 0.0;
boundarycoeffs[i * 3 + 2] = 0.0;
}
else if (bndnames[i] == "line_y")
{
boundarycoeffs[i * 3] = 0.0;
boundarycoeffs[i * 3 + 1] = 1.0;
boundarycoeffs[i * 3 + 2] = 0.0;
}
else if (bndnames[i] == "line_xy_1")
{
boundarycoeffs[i * 3] = 1.0;
boundarycoeffs[i * 3 + 1] = -1.0;
boundarycoeffs[i * 3 + 2] = 0.0;
}
else if (bndnames[i] == "line_xy_2")
{
boundarycoeffs[i * 3] = 1.0;
boundarycoeffs[i * 3 + 1] = 1.0;
boundarycoeffs[i * 3 + 2] = 0.0;
}
else if (bndnames[i] == "line_x_1")
{
boundarycoeffs[i * 3] = 1.0;
boundarycoeffs[i * 3 + 1] = 0.0;
boundarycoeffs[i * 3 + 2] = hwidth;
}
else if (bndnames[i] == "line_x_2")
{
boundarycoeffs[i] = 1.0;
boundarycoeffs[i * 3 + 1] = 0.0;
boundarycoeffs[i * 3 + 2] = -hwidth;
}
else if (bndnames[i] == "line_y_1")
{
boundarycoeffs[i * 3] = 0.0;
boundarycoeffs[i * 3 + 1] = 1.0;
boundarycoeffs[i * 3 + 2] = hwidth;
}
else if (bndnames[i] == "line_y_2")
{
boundarycoeffs[i * 3] = 0.0;
boundarycoeffs[i * 3 + 1] = 1.0;
boundarycoeffs[i * 3 + 2] = -hwidth;
}
else
{
printf("\n error! \n");
}
}
}