c - fseek(f,0,2);如果没有 SEEK_CUR/SEEK_SET 或 SEEK_END,这是如何工作的?

标签 c file fseek

难道我们不应该为 whence 使用 SEEK_CUR/SEEK_SETSEEK_END 吗?它如何只使用固定值?

最佳答案

SEEK_SET/SEEK_CUR/SEEK_END分别为0/1/2,可以使用数字或定义。

在这里查看定义:http://unix.superglobalmegacorp.com/BSD4.4/newsrc/sys/unistd.h.html

/* whence values for lseek(2) */
#define SEEK_SET    0   /* set file offset to offset */
#define SEEK_CUR    1   /* set file offset to current plus offset */
#define SEEK_END    2   /* set file offset to EOF plus offset */

当然,直接使用这些数字是不好的做法,因为它可能会在未来的实现中发生变化(虽然不太可能)

关于c - fseek(f,0,2);如果没有 SEEK_CUR/SEEK_SET 或 SEEK_END,这是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38226713/

相关文章:

无法在 C 中使用 void 变量进行编译

c - 将 .txt 文件中的多行数据扫描到结构数组中

vb.net - 为什么 SHGetFileInfo 改变(当前)文化?

PHP:从文件中的某个点读取

c - 无法从当前位置向后使用 fseek()

c - 是否在任何 stdlib header 中定义了 uint32、int32、uint64、int64 等类型?

C代码: for loop compiles with gcc but doesn't run

java - rundll32 相当于在 Linux 平台中打开和查看文件

algorithm - 估计数据的压缩大小

c - 使用 fseek 编辑文件