文件操作之打开文件(fopen、_wfopen、fopen_s、_wfopen_s)――C语言

匿名 (未验证) 提交于 2019-12-02 23:49:02

 1 #include <stdio.h>  2   3 void OpenFile(FILE **map);    //打开文件  4 void JudgeOpenSuc(FILE *judge);        //判断文件打开是否成功  5   6 int main()  7 {  8     FILE *fp;  9  10     OpenFile(&fp); 11     JudgeOpenSuc(fp); 12  13     return 0; 14 } 15  16 void OpenFile(FILE **map) 17 { 18     (*map) = fopen("E:my.txt", "a+"); 19 } 20  21 void JudgeOpenSuc(FILE *judge) 22 { 23     if (judge != NULL) 24     { 25         printf("Open successfully\n"); 26     } 27     else 28     { 29         printf("Open failure\n"); 30     } 31 }

 1 #include <stdio.h>  2   3 const int SUC = 0;  4   5 void OpenFile(FILE **map, errno_t *err);    //打开文件  6 void JudgeOpenSuc(errno_t err);        //判断文件打开是否成功  7   8 int main()  9 { 10     FILE *fp; 11     errno_t err; 12  13     OpenFile(&fp, &err); 14     JudgeOpenSuc(err); 15  16     return 0; 17 } 18  19 void OpenFile(FILE **map, errno_t *err) 20 { 21     (*err) = fopen_s(map, "E:my.txt", "a+"); 22 } 23  24 void JudgeOpenSuc(errno_t err) 25 { 26     if (err == SUC) 27     { 28         printf("Open successfully\n"); 29     } 30     else 31     { 32         printf("Open failure\n"); 33     } 34 }

 1 #include <stdio.h>  2   3 void OpenFile(FILE **map);    //打开文件  4 void JudgeOpenSuc(FILE *judge);        //判断文件打开是否成功  5   6 int main()  7 {  8     FILE *fp;  9  10     OpenFile(&fp); 11     JudgeOpenSuc(fp); 12  13     return 0; 14 } 15  16 void OpenFile(FILE **map) 17 { 18     (*map) = _wfopen(L"E:my.txt", L"a+"); 19 } 20  21 void JudgeOpenSuc(FILE *judge) 22 { 23     if (judge != NULL) 24     { 25         printf("Open successfully\n"); 26     } 27     else 28     { 29         printf("Open failure\n"); 30     } 31 }

 1 #include <stdio.h>  2   3 const int SUC = 0;  4   5 void OpenFile(FILE **map, errno_t *err);    //打开文件  6 void JudgeOpenSuc(errno_t err);        //判断文件打开是否成功  7   8 int main()  9 { 10     FILE *fp; 11     errno_t err; 12  13     OpenFile(&fp, &err); 14     JudgeOpenSuc(err); 15  16     return 0; 17 } 18  19 void OpenFile(FILE **map, errno_t *err) 20 { 21     (*err) = _wfopen_s(map, L"E:my.txt", L"a+"); 22 } 23  24 void JudgeOpenSuc(errno_t err) 25 { 26     if (err == SUC) 27     { 28         printf("Open successfully\n"); 29     } 30     else 31     { 32         printf("Open failure\n"); 33     } 34 }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!