在Windows中我使用flushall()函数来清空所有缓冲区,但在Linux中,这不工作,我的scanf()函数,而扫描跳过:scanf()函数被跳过的循环
for(i=0;i<n;i++)
{
printf("\nEnter alphabet :");
scanf("%c",&x);
printf("\nEnter frequency :");
scanf("%f",&probability);
/* create a new tree and insert it in
the priority linked list */
p=(treenode*)malloc(sizeof(treenode));
p->left=p->right=NULL;
p->data=x;
p->freq=(float)probability;
head=insert(head,p);
}
输出:
[email protected]:~$ ./a.out
Enter alphabet :a
Enter frequency :2
Enter alphabet :
Enter frequency :a
Enter alphabet :
Enter frequency :2
Enter alphabet :
Enter frequency :a
Enter alphabet :
可能重复的[Scanf在C中跳过while each循环](http://stackoverflow.com/questions/1669821/scanf-skips-every-other-while-loop-in-c) – axiac
In它的当前形式(使用'scanf(“%c”)'这个问题是ma的重复关于'scanf()'的这种行为的其他问题。 – axiac