【发布时间】:2021-12-04 15:13:13
【问题描述】:
当我在命令行中运行代码时,所有功能都在打印功能旁边精确工作。我希望print() 在我输入 p 并按 Enter 时打印节点,但在我之后输入一个字符之前它不会打印。由于我无法弄清楚这一点,您能发现我的错误吗?
print()方法
void print(struct node *root)
{
if (root != NULL)
{
printf("(");
print(root->left);
printf("%d", root->data);
print(root->right);
printf(")");
}
}
main()方法
int main(int argc, char** argv)
{
char input;
int n;
char insertt = 'i';
char printt = 'p';
char searchh = 's';
char deletee = 'd';
struct node *root = NULL;
while(scanf("%c%d", &input, &n) !=-1)
{
if(input==insertt)
{
root = insert(root,n);
}
else if(input==deletee)
{
root = deleteNode(root,n);
}
else if(input==searchh)
{
if(search(root,n))
printf("present\n");
else printf("absent\n");
}
else if(input==printt)
{
print(root);
}
}
return 0;
}
【问题讨论】:
-
这能回答你的问题吗? scanf Getting Skipped
-
尝试将
"%c%d"更改为" %c%d"。阅读重复的帖子以获得更多解释。
标签: c shell debugging terminal