以下代码输出"非法搜索":
#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不可寻找,有什么方法可以做同样的事情吗?
谢谢您的回复.