根据我之前的问题,如果 stdin 来自 pipe
或 terminal,确定
在不同的系统上。stdin
大小的正确而有效的方法是什么
我正在执行以下操作,但是,根据一些评论,这不是正确的方法,它可能适用于也可能不适用于不同的系统。
#include <sys/stat.h>
off_t size(FILE *st_in) {
struct stat st;
if (fstat(fileno(st_in), &st) == 0)
return st.st_size;
return -1;
}
最佳答案
你不能。
你问的和“水龙头里有多少水”一样? :-)
关于c - 确定 C 中 stdin 大小的正确/有效方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4411852/