在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