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; }