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源文件中調用的函數。動態分配的結構數組中的SegFault,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);
我沒有得到任何賽格故障這裏... 後來我打電話......
initialize_fig(0, Qe, 10.0000, 10.0000, fig_point);
的參數實際上通過了變量,但我只是想表明它們是正確的參數,並給出了傳遞值的例子。 反正它擊中
strncpy(fig_point[n].name, name, FIGURE_LEN + 1);
,並停止..段錯誤必須在這裏發生,但爲什麼?
請幫助,解釋並說明如何解決這個問題。謝謝。
請您在回答後再編輯問題。這使得它很混亂。 – mathematician1975