C_C++/C_라이브러리_함수

(C언어) ftell: 현재 파일 포인터의 위치 알아내기

고니자니 2023. 2. 10. 09:50
반응형

#ftell #현재 #파일 #포인터 #위치 #FILE #fseek

 

#include <stdio.h>
long int ftell(FILE *stream);

ftell 함수는 지정한 stream 인수의 파일 포인터의 현재 위치를 반환합니다.

오류가 발생하면 -1을 반환합니다.

 

#define _CRT_SECURE_NO_WARNINGS  // Visual Studio
#include <stdio.h>

int main()
{
	FILE* fp;

	if ((fp = fopen("ftell.txt", "w+")) == NULL)
	{
		printf("파일을 생성할 수 없습니다.\n");
		return -1;
	}
	fprintf(fp, "Tell me about me!");
	printf("%d\n", ftell(fp));
	fclose(fp);

	return 0;
}

ftell 함수의 결과

 

 

반응형