void foundtree(BiTree *root)
{
char x;
fflush(stdin);
scanf("%c",&x);
if(x=='#')
{
*root=NULL;
}
else
{*root=(BiTree)malloc(sizeof(BiTreeNode));
(*root)->data=x;
foundtree(&(*root)->lchild);
foundtree(&(*root)->rchild);
}
}
为什么一定要加缓冲区
```
你不能对输入流调用fflush()
函数,否则的话,你的程序的行为是未定义的。
https://en.cppreference.com/w/c/io/fflush
For input streams (and for update streams on which the last operation was input), the behavior is undefined.
其实如果你是想忽略空白符,只要在%c前加个空格就行了。
scanf(" %c",&x); // %c前添加一个空格,用来忽略任意个空白符(包括空格、制表符和回车)
主要是担心你输入时不是连续输入字符,一旦输入一个字符你就回车,那么就需要清空缓冲区,否则就接收换行符啦