以下代码输出"Illegal seek":
当我运行
谢谢您的回复。
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main() {
errno = 0;
getchar();
getchar();
getchar();
ftell( stdin );
printf( "%s\n", strerror(errno) );
}
当我运行
cat script | ./a.out
或者只是运行./a.out
时,就会出现这个问题。当然,问题出在ftell上。我的问题是:为什么会发生这种情况?我认为stdin是可定位的。fseek也会导致相同的错误。如果stdin不可定位,那么有没有办法做同样的事情呢?谢谢您的回复。