C语言学习(44)

 1 //ferror函数的作用是检查文件中是否有错误,如果有错,则返回非0,否则返回0
 2 //ferror(文件指针)
 3 #include<stdio.h>
 4 #include<stdlib.h>
 5 int main(){
 6     FILE *fp;
 7     if((fp=fopen("file_data.txt","r"))==NULL){
 8         printf("打开文件失败\n");
 9         exit(0);
10     }
11     if(ferror(fp)){
12         printf("打开文件file_data.txt出错\n");
13     }else{
14         printf("打开文件file_data.txt没有错误\n");
15     }
16     fclose(fp);
17     return 0;
18 }

猜你喜欢

转载自www.cnblogs.com/Tobi/p/9239947.html
今日推荐