【发布时间】:2015-04-20 19:38:52
【问题描述】:
在 Windows 中,我使用 flushall() 函数刷新所有缓冲区,但这在 Linux 中不起作用,我的 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);
}
输出:
mayur@mayur-laptop:~$ ./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"),该问题与许多其他有关scanf()行为的问题重复。