Desc :
void perror( const char *string );
string - 오류메세지 앞에 덧붙이고 싶은 문자열
오류에 대한 원인을 출력메세지로 보여준다
Source Code :
#include <stdio.h>
void main()
{
FILE *fp;
int ch;
fp= fopen("C:\\Users\\w4135\\OneDrive\\155test.txt","r");
if (fp == NULL)
{
perror("파일 개방 에러");
}
else
{
ch = fgetc(fp);
if (ferror(fp))
{
perror("파일 읽기 에러");
}
fclose(fp);
}
}
Result :
'C' 카테고리의 다른 글
[C] 157 파일이 존재하는 지 확인하기 _access (1) | 2021.02.01 |
---|---|
[C] 156 임시 파일 이름 만들기 tmpnam (1) | 2021.02.01 |
[C] 154 파일 읽기/쓰기 시 에러 검사하기 (1) | 2021.02.01 |
[C] 153 파일의 끝에 도달했는지 검사하기 feof (1) | 2021.02.01 |
[C] 152 파일 닫기 fclose (1) | 2021.02.01 |