小编Jim*_*Jim的帖子

ftell(stdin)导致非法搜索错误

以下代码输出"非法搜索":

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

int main() {
    errno = 0;
    getchar();
    getchar();
    getchar();
    ftell( stdin );
    printf( "%s\n", strerror(errno) );
}
Run Code Online (Sandbox Code Playgroud)

当我运行"cat script | ./a.out"以及运行"./a.out"时,会发生这种情况.当然,问题在于ftell.我的问题是:为什么会发生这种情况?我认为stdin可以寻找.fseek也会导致同样的错误.如果stdin不可寻找,有什么方法可以做同样的事情吗?

谢谢您的回复.

c file-io ftell

7
推荐指数
1
解决办法
2673
查看次数

标签 统计

c ×1

file-io ×1

ftell ×1