fpos_t类型变量的格式说明符?

Pra*_*ble 3 c file

在这里我只想看到变量的内容pos; 那么什么类型的格式说明符必须用于此?

#include <stdio.h>

void main() {
    FILE *fileptr = fopen("sample.txt", "r+");
    fpos_t pos;
    int val = fgetpos(fileptr, &pos);
}
Run Code Online (Sandbox Code Playgroud)

chq*_*lie 5

fpos_t 在C标准中定义为:

fpos_t

这是一种完整的对象类型,而不是数组类型,能够记录唯一指定文件中每个位置所需的所有信息.

此类型不一定是标量,可以定义为struct具有多个成员的类型.没有printf格式以可读的方式输出它.某些系统可能需要执行复杂的任务来处理文本文件,而不是每台计算机都是PC.

如果您对实现感兴趣,可以将其内容转储为十六进制字节:

#include <stdio.h>

int main(void) {
    FILE *fileptr = fopen("sample.txt", "r+");
    fpos_t pos;

    if (fileptr && fgetpos(fileptr, &pos) == 0) {
        printf("contents of pos: ");
        for (size_t i = 0; i < sizeof(pos); i++) {
            printf("%02X", ((unsigned char *)&pos)[i]);
        }
        printf("\n");
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在许多现代系统中,您将得到0000000000000000因为64位整数足以表示文件中偏移所需的所有信息,但您不应该依赖于此.