#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
FILE *fp;
if((fp = fopen(argv[1], "rb")) == NULL ) {
fprintf(stderr,"ファイルオープンエラー\n");
exit(EXIT_FAILURE);
}
fseek(fp, 10L, SEEK_SET);
printf("ファイル位置 = %ld\n",ftell(fp));
fseek(fp, -5L, SEEK_CUR);
printf("ファイル位置 = %ld\n",ftell(fp));
fseek(fp, 0L, SEEK_END);
printf("ファイル位置 = %ld\n",ftell(fp));
fseek(fp, 0L, SEEK_SET);
printf("ファイル位置 = %ld\n",ftell(fp));
fclose(fp);
return 0;
}
【実行結果例】
ファイル位置 = 10 ファイル位置 = 5 ファイル位置 = 661 ファイル位置 = 0
▼戻る▼
「初心者のためのポイント学習C言語」 Copyright(c) 2000-2004 TOMOJI All Rights Reserved