c语言 13-2

Posted 小虾米2018

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c语言 13-2相关的知识,希望对你有一定的参考价值。

1、

#include <stdio.h>

int main(void)
{
    FILE *fp; // 打开文件前,必须定义FILE*型指针变量 
    
    char file[128];
    printf("please input the file: "); scanf("%s", file);
    
    fp = fopen(file, "r");  //利用fp指针变量来判断文件是否存在 
    if(fp == NULL)
        printf("\\afile does not exist!\\n");
    else
    {
        fp = fopen(file, "w");  //以写入的方式打开文件,会清空文件的内容 
        printf("\\afile cleared successfully!\\n");
        fclose(fp);
    }
    
    return 0;
}

 

以上是关于c语言 13-2的主要内容,如果未能解决你的问题,请参考以下文章