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. "); else { printf("File exists. "); 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. "); else { fp = fopen(filename, "w"); printf("File cleared successfully. "); fclose(fp); } return 0; }