c语言里malloc未定义,C语言中malloc的问题

int i;

int j;

char filename[200];

FILE* fread;

Item* item_1;/*

Item有两个域,第一个域dimension_1是用来存放数据

第二个域clusterID,现在被用来存放相同的数据出现的个数

*/

//test

for( i = 1; i <= cluster_count; i++ )

printf("the size of cluster %d is %d\n", i, counter[i]);

//test END

for( i = 1; i <= 1; i++ )

{

printf("@@@@@@@@%d\n", counter[i]);

sprintf(filename, ".//ClusterProcess_1dimension//round%d_cluster%d.data", count, i);

if( NULL == (fread = fopen(filename, "r")))

{

printf("open file(%s) error!\n");

exit(0);

}

item_1 = (Item*)malloc(sizeof(struct Item) * (counter[i] + 1));

/*

if( !item_1 )

{

printf("item malloc error %d\n", i);

exit(0);

}

*/

printf("@@@@@@@@%d\n", counter[i]);

/*

for( j = 1; j <= counter[i]; j++ )

{

if( 1 != fscanf(fread, "%d ", &item_1[j].dimension_1))

{

printf("scanf error: %s : %d", filename, j);

exit(0);

}

printf("cluster_center : %d -- %d \n", i, j);

}

*/

free(item_1);

//fclose(fread);

}

为什么第32行和第17行的输出结果不一致,出现了乱码,假如去掉24行则正常。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值