c语言 13-1、13-2

13 - 1、

#include <stdio.h>

int main(void)
{
    FILE *fp;
    char filename[FILENAME_MAX];
    printf("filename: "); scanf("%s", filename);
    
    if((fp = fopen(filename, "r")) == NULL)
        printf("\aFile does not exist.\n");
    else
    {
        printf("File exists.\n");
        fclose(fp); 
    }
    return 0;
}

 

13 - 2、

#include <stdio.h>

int main(void)
{
    FILE *fp;
    char filename[FILENAME_MAX];
    printf("filename: "); scanf("%s", filename);
    
    if((fp = fopen(filename, "r")) == NULL)
        printf("\aFile does not exist.\n");
    else
    {
        fp = fopen(filename, "w");
        printf("File cleared successfully.\n");
        fclose(fp);
    }
    return 0;
}

 

posted @ 2021-06-10 17:39  小鲨鱼2018  阅读(75)  评论(0编辑  收藏  举报