工作生活

C基础-文件操作

2020-02-20  本文已影响0人  伊泽瑞额

这里的“打开”和“关闭”可调用标准库 stdio.h 中的 fopen 和 fclose 函数实现。
如:FILE * fopen(char *filename, char *mode);
filename:文件路径
mode:文件打开模式 (r:只读)(w:写)(“rw” 表示读写)(rb:二进制读)(wb:二进制写)

void main(){
    FILE  *fp1, *fp2;
    fp1=fopen("D:\\VisualStudio\\work_place\\text01.txt", "r");
    fp2 = fopen("D:\\VisualStudio\\work_place\\text02.txt", "w");

    if (NULL==fp1){
        printf("Failed to open the file !\n");
        exit(0); //终止程序,stdlib .h头文件中
    }
    if (NULL == fp2){
        printf("Failed to open the file !\n");
        exit(0); //终止程序,stdlib .h头文件中
    }

    fclose(fp1);
    fclose(fp2);
    getchar();
    
}

上一篇 下一篇

猜你喜欢

热点阅读