1
int main(void)
{
int byte;
int i= 0,zj,di;
int n = 0;
char y[100];
char e[100];
char f1[100];
int **arr;
int *arr1;
if(argc < 2)
{
printf("Input file does not exist:\n");
printf("Enter arguments in the following manner:\n");
printf("<./a.out> <input_file> <output_file>:\n");
return 0;
}
fp1=fopen(argv[1],"r");
if (fp1 == NULL){
printf("input file does not exist.\n");
return EOF;
}
if(argc < 3)
{
fp=stdout;
}
else
fp=fopen(argv[2],"w");
for(i=0;i<4;i++){
fscanf(fp1,"%s",y);
a = atoi(y);
if(i==0) zj = a;
if(i==1) di = a;
if(i==2) ck = a;
if(i==3) n = a;
}
arr =(int**) memory_Malloc(n*sizeof(int*));
for (i=0; i<n; ++i){
arr[i] = memory_Malloc(2*sizeof(int));
}
arr1=(int*)memory_Malloc(di*sizeof(int));
for (i=0;i<zj;i++){
arr1[i]=0;
}
fgets(y,100,fp1);
count=0;
while (!feof(fp1)){
fgets(y, 100, fp1);
if(strlen(y)<=1)
break;
if(count>=zj)
break;
sscanf(y,"%s %s", e, f1);
arr[count][0] = atoi(e);
arr[count][1] = atoi(f1);
count++;
}
for(i=0; i<n ; i++)
{
memory_Free(arr[i],2*sizeof(int));
}
memory_Free(arr,n*sizeof(int));
memory_Free(arr1,di*sizeof(int));
fclose(fp1);
// intermediate code and then //
fclose(fp);
}
1,600,000 bytes in 1 blocks are definitely lost in loss record 2 of 2
==15369== at 0x43DC38B: malloc (vg_replace_malloc.c:149)
==15369== by 0x8056080: memory_Malloc (memory.c:567)
==15369== by 0x804D51B: main (symbol.h:649)
==15369==
==15369== LEAK SUMMARY:
==15369== definitely lost: 1,600,000 bytes in 1 blocks.
==15369== possibly lost: 0 bytes in 0 blocks.
==15369== still reachable: 96 bytes in 12 blocks.
==15369== suppressed: 0 bytes in 0 blocks.
[編輯]
POINTER memory_Malloc(unsigned int Bytes) // same as malloc in standard C
void memory_Free(POINTER Freepointer, unsigned int Size)
int * PRECEDENCE
PRECEDENCE P
symbol.h 649 P = memory_Malloc(sizeof(int[symbol__MAXSIGNATURE]));
我把你的發佈代碼儘可能地清理乾淨 - 這真是一團糟 - 如果你想讓人們花時間閱讀你的代碼並幫助你,請在代碼格式化方面加倍努力。 – 2010-12-09 11:26:16