
fsetpos
433
const int reclength_file = sizeof(record);
const long seek_id = 123L;
FILE* fp = fopen("records", "rb");
if (fp == NULL)
{
perror("Unable to open records file");
}
else
{
do
{
if (1 > fread(&cur_rec.id, sizeof(long), 1, fp))
{
fprintf(stderr, "Record with ID %ld not found.\n", seek_id);
break;
}
else
//
レコードの残りは読み飛ばす
{
if (fseek(fp, reclength_file - sizeof(long), 1))
{
perror("fseek failed");
break;
}
}
} while (cur_rec.id != seek_id);
■
参照
●
fgetpos()
,
fsetpos()
,
ftell()
,
rewind()
fsetpos
ファイル位置指示子を、前に記録した位置に設定する
#include <stdio.h>
int fsetpos(FILE*
fp
, const fpos_t*
ppos
);
fsetpos()
関数は
FILE
ポインタ引数で指定したファイルの位置指示子を設定する。新位
置の値へのポインタである
ppos ...