我已這種方式定義的動態數組:在一個循環中動態陣列
double *n_data ;
int n_data_c = 0, n_cnt = 0;
n_data_c = count_lines_of_file("abnorm");
n_data = (double *)malloc(n_data_c * sizeof(double));
我計算距離和要這樣做:
n_cnt++;
n_data[n_cnt] = distance;
但在這裏返回segmentation fault
:n_data[n_cnt] = distance;
我想知道我是否做錯了什麼。
在C中,你不應該使用'malloc'結果(http://stackoverflow.com/a/605858/440558)。 –
您的來源有很多錯誤。 – BLUEPIXY