C fclose() 파일 닫기 함수
fopen()으로 열기한 파일 사용을 종료합니다.
- 헤더: stdio.h
- 형태: int *fclose(FILE *stream)
- 인수: FILE *stream 닫고자 하는 FILE 포인터
- 반환: int 정상적으로 닫았다면 0을, 오류가 발생하면 EOF를 반환합니다.
C언어 fclose() 예제
#include <stdio.h>
#include <stdlib.h>
int main( void)
{
FILE *fp;
char *str;
int buff_size;
buff_size = 1024;
if ( fp = fopen( "./test.c", "r")){
str = malloc( buff_size+5);
while( fgets( str, buff_size, fp))
printf( "%s", str);
fclose( fp);
free( str);
}
return 0;
}
C언어 fclose() 예제 실행 결과
]$ ./a.out
#include <stdio.h>
#include <stdlib.h>
int main( void)
{
FILE *fp;
char *str;
int buff_size;
buff_size = 1024;
if ( fp = fopen( "./test.c", "r")){
str = malloc( buff_size+5);
while( fgets( str, buff_size, fp))
printf( "%s", str);
fclose( fp);
free( str);
}
return 0;
}]$
'컴퓨터 > 프로그래밍' 카테고리의 다른 글
C언어 fgetc 함수 파일에서 문자 한 개 읽기 (0) | 2020.03.13 |
---|---|
C언어 scanf 함수 표준 입력장치로부터 서식에 맞춘 입력 받기 (0) | 2020.03.13 |
C언어 puts 함수 표준 출력에 문자열 출력 (0) | 2020.03.13 |