#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