2 u012751989 u012751989 于 2013.12.30 20:14 提问

c语言的问题 求助。。。。

#include
#include
#include
typedef struct{
char *key;
char *val;
struct dnode *next;
}dnode;

typedef struct{
struct dnode *a;
struct dnode *b;
struct dnode *c;
struct dnode *d;
struct dnode *e;
struct dnode *f;
struct dnode *g;
struct dnode *h;
struct dnode *i;
struct dnode *j;
struct dnode *k;
struct dnode *l;
struct dnode *m;
struct dnode *n;
struct dnode *o;
struct dnode *p;
struct dnode *q;
struct dnode *r;
struct dnode *s;
struct dnode *t;
struct dnode *u;
struct dnode *v;
struct dnode *w;
struct dnode *x;
struct dnode *y;
struct dnode *z;
}bnode;

dnode *d_empty()
{
return NULL;
}

bnode *b_empty()
{
return NULL;
}

dnode *new_Node(char *key ,char *val,dnode *t)
{
if (t==NULL)
{
strcpy(t->key,key);
strcpy(t->val,val);
t->next=NULL;
return t;
}
else
{
t->next=new_Node(key,val,t->next);
return t;
}

}
/*
dnode *new_NodeNode(dnode *t,dnode *d)
{
if (t==NULL)
{
t=d;
return t;
}
else
{
t->next=new_NodeNode(key,val,t->next);
return t;
}

}

*/
dnode *find_Node(char *key ,dnode *t)
{
if (t==NULL)
{
return NULL;
}
else
{
if(strcmp(key,t->key)==0)
return t;
else
{
return find_Node(key,t->next);
}
}
}

dnode *delete_Node(char *key ,dnode *t)
{
if (t==NULL)
{
return NULL;
}
else
{
if(strcmp(key,t->key)==0)
{
return t->next;
}
else
{
t->next=delete_Node(key,t->next);
return t;
}
}
}

bnode *d_insert(char *key,char *val,bnode *kk)
{
switch(key[0])
{
case 'a':kk->a=new_Node(key,val,kk->a);break;
case 'b':kk->b=new_Node(key,val,kk->b);break;
case 'c':kk->c=new_Node(key,val,kk->c);break;
case 'd':kk->d=new_Node(key,val,kk->d);break;
case 'e':kk->e=new_Node(key,val,kk->e);break;
case 'f':kk->f=new_Node(key,val,kk->f);break;
case 'g':kk->g=new_Node(key,val,kk->g);break;
case 'h':kk->h=new_Node(key,val,kk->h);break;
case 'i':kk->i=new_Node(key,val,kk->i);break;
case 'j':kk->j=new_Node(key,val,kk->j);break;
case 'k':kk->k=new_Node(key,val,kk->k);break;
case 'l':kk->l=new_Node(key,val,kk->l);break;
case 'm':kk->m=new_Node(key,val,kk->m);break;
case 'n':kk->n=new_Node(key,val,kk->n);break;
case 'o':kk->o=new_Node(key,val,kk->o);break;
case 'p':kk->p=new_Node(key,val,kk->p);break;
case 'q':kk->q=new_Node(key,val,kk->q);break;
case 'r':kk->r=new_Node(key,val,kk->r);break;
case 's':kk->s=new_Node(key,val,kk->s);break;
case 't':kk->t=new_Node(key,val,kk->t);break;
case 'u':kk->u=new_Node(key,val,kk->u);break;
case 'v':kk->v=new_Node(key,val,kk->v);break;
case 'w':kk->w=new_Node(key,val,kk->w);break;
case 'x':kk->x=new_Node(key,val,kk->x);break;
case 'y':kk->y=new_Node(key,val,kk->y);break;
case 'z':kk->z=new_Node(key,val,kk->z);break;
}

return kk;

}

bnode *d_search(char *key ,bnode *kk)
{
switch(key[0])
{
case 'a':return find_Node(key,kk->a);
case 'b':return find_Node(key,kk->b);
case 'c':return find_Node(key,kk->c);
case 'd':return find_Node(key,kk->d);
case 'e':return find_Node(key,kk->e);
case 'f':return find_Node(key,kk->f);
case 'g':return find_Node(key,kk->g);
case 'h':return find_Node(key,kk->h);
case 'i':return find_Node(key,kk->i);
case 'j':return find_Node(key,kk->j);
case 'k':return find_Node(key,kk->k);
case 'l':return find_Node(key,kk->l);
case 'm':return find_Node(key,kk->m);
case 'n':return find_Node(key,kk->n);
case 'o':return find_Node(key,kk->o);
case 'p':return find_Node(key,kk->p);
case 'q':return find_Node(key,kk->q);
case 'r':return find_Node(key,kk->r);
case 's':return find_Node(key,kk->s);
case 't':return find_Node(key,kk->t);
case 'u':return find_Node(key,kk->u);
case 'v':return find_Node(key,kk->v);
case 'w':return find_Node(key,kk->w);
case 'x':return find_Node(key,kk->x);
case 'y':return find_Node(key,kk->y);
case 'z':return find_Node(key,kk->z);
}
}

bnode *d_delete(char *key , bnode *kk)
{
switch(key[0])
{
case 'a':kk->a=delete_Node(key,kk->a);break;
case 'b':kk->b=delete_Node(key,kk->b);break;
case 'c':kk->c=delete_Node(key,kk->c);break;
case 'd':kk->d=delete_Node(key,kk->d);break;
case 'e':kk->e=delete_Node(key,kk->e);break;
case 'f':kk->f=delete_Node(key,kk->f);break;
case 'g':kk->g=delete_Node(key,kk->g);break;
case 'h':kk->h=delete_Node(key,kk->h);break;
case 'i':kk->i=delete_Node(key,kk->i);break;
case 'j':kk->j=delete_Node(key,kk->j);break;
case 'k':kk->k=delete_Node(key,kk->k);break;
case 'l':kk->l=delete_Node(key,kk->l);break;
case 'm':kk->m=delete_Node(key,kk->m);break;
case 'n':kk->n=delete_Node(key,kk->n);break;
case 'o':kk->o=delete_Node(key,kk->o);break;
case 'p':kk->p=delete_Node(key,kk->p);break;
case 'q':kk->q=delete_Node(key,kk->q);break;
case 'r':kk->r=delete_Node(key,kk->r);break;
case 's':kk->s=delete_Node(key,kk->s);break;
case 't':kk->t=delete_Node(key,kk->t);break;
case 'u':kk->u=delete_Node(key,kk->u);break;
case 'v':kk->v=delete_Node(key,kk->v);break;
case 'w':kk->w=delete_Node(key,kk->w);break;
case 'x':kk->x=delete_Node(key,kk->x);break;
case 'y':kk->y=delete_Node(key,kk->y);break;
case 'z':kk->z=delete_Node(key,kk->z);break;
}
return kk;
}

void main()
{
char *cmd;
cmd=malloc(100);
char *key;
key=malloc(100);
char *val;
val=malloc(100);

   bnode *t;
   t=malloc(sizeof(bnode));
   dnode *u;
   u= malloc(sizeof(dnode));
   u->key=malloc(100);
   u->val=malloc(100);
   u->next=NULL;

   t->a=u;
   t->b=u;
   t->c=u;
   t->d=u;
   t->e=u;
   t->f=u;
   t->g=u;
   t->h=u;
   t->i=u;
   t->j=u;
   t->k=u;
   t->l=u;
   t->m=u;
   t->n=u;
   t->o=u;
   t->p=u;
   t->q=u;
   t->r=u;
   t->s=u;
   t->t=u;
   t->u=u;
   t->v=u;
   t->w=u;
   t->x=u;
   t->y=u;
   t->z=u;



   while (scanf("%s", cmd) != EOF){
    if(strcmp(cmd, "insert") == 0){
        scanf("%99s\t%99s", key, val);
        t = d_insert(key, val, t);
    }else if(strcmp(cmd, "delete") == 0){
        scanf("%99s", key);
        t = d_delete(key, t);
    }else if(strcmp(cmd, "search") == 0){
        scanf("%99s", key);
        u = d_search(key, t);
        if(u != NULL){
            printf("%s\n", u->val);
        }else{
            printf("(not found)\n");
        }
    }else if(strcmp(cmd, "quit") == 0){
        break;
    }/*else if(strcmp(cmd, "show") == 0){
        btree_print(t, 0);
    }*/else{
        printf("command not found: %s\n", cmd);
    }

    cmd[0] = key[0] = val[0] = '\0';
}

}
insert一运行就崩溃 咋回事

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!