반응형

fell(3)

#include <stdio.h>

long ftell(FILE *stream);

stream의 현재 읽기/쓰기 위치를 얻습니다.

 

 

파라미터

stream
    - 읽거나 쓰기 위한 현재 위치를 얻을 stream

 

RETURN

0 이상
    - 현재 stream의 읽거나 쓸 수 있는 위치

-1
    - 오류가 발생하였으며, 상세한 오류는 errno에 설정됩니다.
     EBADF : stream이 위치를 이동시킬 수 있는 stream이 아닙니다.

 


활용 현황

 

Sample) 파일의 크기를 간단하게 구하는 방법

#include <stdio.h>
#include <string.h>
#include <errno.h>

int main(int argc, char *argv[])
{
    FILE *fp;
    int   file_size;

    if(argc != 2) {
        return 1;
    }

    if((fp = fopen(argv[1], "r")) == NULL) {
        fprintf(stderr, "%s file open error: %s\n", argv[1], strerror(errno));
        return 1;
    }

    /* file의 끝으로 이동 */
    fseek(fp, 0, SEEK_END);
    file_size = ftell(fp);
    printf("%s file size: %d bytes", argv[1], file_size);

    fclose(fp);
}

 


see also :

    File 속성 정보 및 파일 관리 Library

    Directory 정보 조회 및 관리 Library

    System Call File I/O Library

    Stream File I/O Library

 

 

반응형
블로그 이미지

자연&사람

행복한 개발자 programmer since 1995.

,