|
句柄就是文件的指针。
函数原型:
#include <stdio.h>
int fgetpos(FILE *stream, fpos_t *pos); 函数执行成功则返回 0 ,失败则返回 -1 。
测试代码:
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
int main()
{
fpos_t position;
FILE *stream;
char mingyan[1000];
char *p = mingyan;
stream = fopen("my4.txt", "r");
if (stream == NULL){
perror("errno");
exit(1);
}
fread(p, 3, 1, stream);
fgetpos(stream, &position);
printf("pos is %d\n", position);
printf("pos is %d\n", position.__pos);
fclose(stream);
return 0;
} 运行及输出:beyes@linux-beyes:~/BBS/3ins/ins> ./read.exe
pos is 3
pos is 3 程序中,注意一点,其实 fpos_t 是个结构体类型。它有一个成员是 __pos ,指的就是这个指针的位置。
直接用结构体名来输出,输出的是结构体中第一个成员的值。
这个 fpos_t 类型在 stdio.h 中是这么定义的:
typedef _G_fpos_t fpos_t; 而 _G_fpos 在 <_G_config.h> 中定义如下
typedef struct
{
__off_t __pos;
__mbstate_t __state;
} _G_fpos_t; |
|