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行则正常。
解决方案
20
counter[i] 的声明?