#include <time.h>
int perm_table[255];
float rand_vectors[255][3];
initialize_random_numbers()
{
int i;
float tmp[3], length;
for (i=0; i<255; i++)
{
perm_table[i] = rand() % 255;
tmp[0] = (float)(rand() % 1000);
tmp[1] = (float)(rand() % 1000);
tmp[2] = (float)(rand() % 1000);
printf("\n%i", i);
memcpy(rand_vectors[i], tmp, sizeof(float)*3);
}
}
運行此打印每一個從0到253 (上255),給人一種分段錯誤之前。段錯誤,想不通爲什麼
注出這條線
perm_table[i] = rand() % 255;
去除錯誤。
我完全被這個打敗了。任何幫助?
請不要將標籤置於問題標題中。 – 2012-02-28 21:45:46
適用於[ideone](http://ideone.com/FQxzR)。你確定這是你正在調用的代碼嗎?如果'perm_table'的大小是254,它就符合這個錯誤。或者它可能在代碼中的其他地方? – amit 2012-02-28 21:47:52
您是否嘗試編譯並單獨運行此代碼?它應該工作得很好!問題一定在其他地方。 – jweyrich 2012-02-28 21:49:56