C/C++ 언어 ftell() 함수를 사용하여 파일의 현재 위치를 출력하는 예제 프로그램


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* ftell() 함수를 사용하여 파일의 현재 위치를 출력하는 예제 프로그램 */
#include <stdio.h>
#include <stdlib.h>
 
void main(void) {
  long current_position ;
  FILE *fp;
  char buffer[81= {0,};
  char filename[20= {0,};
 
  printf("입력 파일의 이름을 입력하시오:");
  gets(filename);
  if ((fp = fopen(filename,"rb")) == NULL ) {
    printf("파일을 개방할 수 없습니다.\n");
    exit(0);
  }
  fread(&buffer,sizeof(char),80,fp);
  if ((current_position = ftell(fp)) == -1L)
    printf("ftell()함수 실패!\n");
  else
    printf("현재 위치는 파일의 시작 위치에서  %ld 바이트 떨어져 있습니다\n",
    current_position);
}
 
cs


C/C++ 언어 ftell() 함수를 사용하여 파일의 현재 위치를 출력하는 예제 프로그램


file. txt

1
hello world!
cs



+ Recent posts