これは私のコードの一部です...そして私は私が立ち往生しているいくつかの主要な問題を抱えています...私がこれまでに見ることができる問題のほとんどは修正されました...しかし私はまだメモリを解放する場所に迷っています。これは、プログラムを終了したときのエラーメッセージです:S
HEAP SUMMARY:
==15468== in use at exit: 20 bytes in 1 blocks
==15468== total heap usage: 1 allocs, 0 frees, 20 bytes allocated
==15468==
==15468== 20 bytes in 1 blocks are definitely lost in loss record 1 of 1
==15468== at 0x4025BD3: malloc (vg_replace_malloc.c:236)
==15468== by 0x8048601: newnode (myassignment.c:27)
==15468== by 0x804885E: insertavl (myassignment.c:88)
==15468== by 0x8048B33: main (myassignment.c:156)
==15468==
==15468== LEAK SUMMARY:
==15468== definitely lost: 20 bytes in 1 blocks
==15468== indirectly lost: 0 bytes in 0 blocks
==15468== possibly lost: 0 bytes in 0 blocks
==15468== still reachable: 0 bytes in 0 blocks
==15468== suppressed: 0 bytes in 0 blocks
==15468==
==15468== For counts of detected and suppressed errors, rerun with: -v
==15468== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 13 from 8)
typedef struct node *tree;
struct node {
int data;
char name;
int height;
struct node *left;
struct node *right;
};
static tree newnode(int d,char n){
tree t = malloc(sizeof(struct node));
t->data = d;
t->name=n;
t->left = NULL;
t->right = NULL;
memoize(t);
return t;
}
static tree modnode(int d, char n,tree t){
if (d > t->data){
t->data=d;
t->name=n;
t->right = t->right;}
else{
t->data=t->data;
t->name=t->name;
t->right = t->right;}
return t;
}
tree insertavl(tree t, int d,const char *n){
if (t == NULL) return newnode(d,*n);
else if (t->name==*n) return modnode(d,*n,t->right);// <=========(1)
else {
printf("went right");
setright(t, insertavl(t->right, d,n));
}
return t;
}
int main(void) {
int i = 0;
char foo[11];
int c;
tree t= NULL;
for(c=0;c<=1000;c++) {
i = readstring(foo,10);
if(i == 0) break;
if (strcmp("score",foo)==0){
int a=0;
int point;
char n[21];
printf ("Enter name \n");
a=readstring (n,20);
printf ("Enter score \n");
scanf("%d", &point);
t=insertavl(t,point,n);}
if (strcmp("highscore",foo)==0){
printf ("%d \n", highsc(t));}
if (t==NULL){
printf ("false");}
}
return 0;
}
私のプログラムは効率的ではないことは知っていますが、最初にエラーを修正したいと思います。