トップページ > キーワード検索 > ftell()
C言語規格
C言語(その他)
プログラム
その他
ftell()
機能 ストリームのファイル位置を取得することを表す。
定義 #include <stdio.h>

long int ftell ( FILE * stream );
引数
streamストリーム(FILE)へのポインタ
戻り値 成功した場合は、ファイル位置を返す。
失敗した場合は、-1Lを返し、処理系定義の正の値をerrnoに格納する。
実装例
#include <stdio.h>

int main(void)
{
    FILE *fp;
    long int pos;
    int c;
    
    fp = fopen("test.txt", "r");
    
    if (NULL != fp) {
        
        pos = ftell(fp);
        c = fgetc(fp);    /* ファイル位置が1つ進む */
        printf("pos=%ld c=%c\n", pos, c);
        
        pos = ftell(fp);
        c = fgetc(fp);    /* ファイル位置が1つ進む */
        printf("pos=%ld c=%c\n", pos, c);
        
        fclose(fp);
    }
    
    return 0;
}
(test.txtの内容)
Hello World.
実行結果
pos=0 c=H
pos=1 c=e





inserted by FC2 system