有关动态二维数组释放的问题,求解答。
本帖最后由 maspacious 于 2013-10-18 14:45:22 编辑 这是我程序中的一部分。但是我想释放申请的二维数组就会出错。其他都正常。
#define VERTEX_NUM 5
#define LABEL_NUM 6
t = (int **)malloc(sizeof(int *)*(VERTEX_NUM+1));
t = (int **)malloc(sizeof(int *)*(VERTEX_NUM+1));
if(t==NULL)
{
printf("-----*t*-----malloc failed\n");
return -1;
}
for (i=0; i<=LABEL_NUM; ++i)
{
t[i] = (int *)malloc(sizeof(int)*(LABEL_NUM+1));
if( NULL == t[i])
{
printf("-----*t-----malloc failed\n");
return -1;
}
}
这是我写的一个释放函数
c malloc
int Releaset()
{
if(t != NULL)
{
for (int i=0; i <=VERTEX_NUM; ++i)
free(t[i]);
free(t);
return 1;
}
else
return -1;
}
[解决办法]
没有,咱俩的申请本质是一样的