반응형
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 :
반응형
'C언어 header > stdio.h' 카테고리의 다른 글
rewind(3) - stream 읽기/쓰기 위치를 처음으로 (0) | 2019.09.24 |
---|---|
fflush(3) - stream buffer를 쓰기를 수행하여 비움 (0) | 2019.09.24 |
fseek(3) - stream 읽기/쓰기 위치변경 (0) | 2019.09.24 |
fputs(3) - stream으로 1라인 쓰기 (0) | 2019.09.24 |
fputc(3) - stream으로 1바이트 쓰기 (0) | 2019.09.24 |