注册 登录
编程论坛 数据结构与算法

没有错误,为什么不能运行,请指教

班哥 发布于 2012-12-09 15:16, 327 次点击
#include<stdio.h>
#include<malloc.h>
typedef struct node
{
    int data;
    struct node *lchild,*rchild;
}BT;
BT* createtree()
{
    BT *bt;
    char x;
    scanf("%c",&x);
    if(x=='0')bt=NULL;
    else
    {
        bt=(BT*)malloc(sizeof(BT));
        bt->data =x;
        bt->lchild =createtree();
        bt->rchild =createtree();
    }
     return bt;
}
int main()
{
    int i;
    while(1)
    {
        printf("\n\t\t\t* * * * * * * * * * * * * * * * * * * *");
        printf("\n\t\t\t       1.建树");
        printf("\n\t\t\t       2.");
        printf("\n\t\t\t       3.");
        printf("\n\t\t\t       4.");
        printf("\n\t\t\t       5.");
        printf("\n\t\t\t       6.");
        printf("\n\t\t\t       7.");
        printf("\n\t\t\t       8.");
        printf("\n\t\t\t       0.");
        printf("\n\t\t\t* * * * * * * * * * * * * * * * * * * *");
        printf("\n请输入你要进行的操作序号(0---9):");
        scanf("%d",i);
        switch(i)
        {
        case 1:createtree();break;
        case 2:break;
        case 3:break;
        case 4:break;
        case 5:break;
        case 6:break;
        }
    }
    return 0;
}
2 回复
#2
yuccn2012-12-09 15:53

        scanf("%d",i);

这个改成
        scanf("%d",&i);
楼主太大意了
#3
思小宏2012-12-14 13:41
printf("\n请输入你要进行的操作序号(0---9):");
        scanf("%d",i);
        switch(i)
        {
        case 1:createtree();break;

你的那个scanf里的i没有加取地址符
1