清空stdin使用fpurge(stdin)出现错误;

3

这是我试图在Ubuntu 14.04上使用GCC编译器编译的程序部分。

#include<stdio.h>
#include<string.h>

main() {
    int i;
    char str[50], pat[3];
    char sep;
    printf("Enter the sting to seperate\n ");
    scanf("%s", str);
    fpurge(stdin);
    printf("Enter the patern in Numbers to seperate Example : 1 2 3\n");
    //__fpurge(stdin);
    scanf("%s", pat);
    fpurge(stdin);
    printf("Enter the seperator Example: ; or enter ,space");
    scanf("%c", &sep);
}

以下是错误信息:

 /tmp/cc0bHLkO.o: In function `main':
 str_sepert.c:(.text+0x4d): undefined reference to `fpurge'
 str_sepert.c:(.text+0x95): undefined reference to `fpurge'
 collect2: error: ld returned 1 exit status

1
根据man页面,在Linux下fpurge不可用。您需要自己编写。此外,请注意该页面上的内容:通常希望丢弃输入缓冲区是错误的。 - Kninnug
感谢您的回复。我使用了 "__fpurge()",问题得到解决。 - user3111
1个回答

6

2
谢谢您的回复。我使用了 "__fpurge()",问题得到解决。 - user3111
我应该补充一下,你可以更新你的 include 来获取你想要的函数,但看起来你已经知道了。 - John
我从你给的链接中得到了更多的解释。谢谢。 - user3111

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接