gpt4 book ai didi

无法从用户读取字符

转载 作者:太空宇宙 更新时间:2023-11-04 08:43:27 25 4
gpt4 key购买 nike

<分区>

在此代码中,我正在创建一个二叉树,直到用户需要节点数。但是在从用户那里获取输入时它在某处失败了..

   struct node *createTree(struct node *root)
{
int n;
char ch;
struct node *t1;
t1=(struct node *)malloc(sizeof(struct node));
printf("Enter Element\n");
scanf("%d",&n);
if(root==NULL)
{
t1->data=n;
t1->left=NULL;
t1->right=NULL;
root=t1;
}

printf("do you want to add node at left?\n");

这不能正常工作

scanf("%c",&ch);

  if(ch=='y')
{
t1->left=createTree(t1->left);

}


printf("do you want to add node at right?\n");
scanf("%c",&ch);

if(ch=='y')
{
t1->right=createTree(t1->right);

}




return root;



}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com