typedef struct {
double x;
double y;
long out_x;
long out_y;
} coords;
typedef struct {
char name[FIGURE_LEN + 1];
int coordcount, size_tracker;
coords *coordinate;
} fig;
fig figure;
fig * figpoint;
这是从 parser.c 源文件中调用的函数。
void initialize_fig(int n, char * name, double x, double y,
fig *fig_point)
{
printf("inside function\n");
strncpy(fig_point[n].name, name, FIGURE_LEN + 1);
fig_point[n].size_tracker = 1;
fig_point[n].coordinate = malloc(sizeof(coords) * fig_point[n].size_tracker);
assert(fig_point[n].coordinate != NULL);
fig_point[n].coordcount = 0;
fig_point[n].coordinate[fig_point[n].coordcount].x = x;
fig_point[n].coordinate[fig_point[n].coordcount].y = y;
}
void create_FigArray(fig * fig_point, int fig_size)
{
fig_point = malloc(sizeof(fig) * fig_size);
assert(fig_point != NULL);
fig_point = &figure
}
我首先像这样调用create_FigArray ...
create_FigArray(fig_point, 16);
我在这里没有seg错误......但后来我打电话......
initialize_fig(0, Qe, 10.0000, 10.0000, fig_point);
参数实际上是通过变量传递的,但我只是想表明它们是正确的参数,并举例说明传递了什么值。无论如何它击中
strncpy(fig_point[n].name, name, FIGURE_LEN + 1);
并停止.. segfault 必须在这里发生,但为什么呢?!
请帮助,解释并展示如何解决这个问题。谢谢你。