我有一个定义为的结构
struct new{
int x;
int y;
unsigned char *array;
};
我希望数组是一个根据用户输入动态初始化的数组。内部主要功能:
struct new *sbi;
sbi->array = (unsigned char*)malloc(16 * sizeof(unsigned char));
for(i=0; i<16; i++)
{
sbi->array[i] = 0;
}
for(i=0; i<16; i++)
printf("Data in array = %u\n", (unsigned int)sbi->array[i]);
我确定我对 malloc 做错了什么,但我没有得到它 - 它只是不断给出分段错误。