#include< stdio.h >
int main()
{
FILE *fp; /* file pointer*/
char fName[20];
printf("Enter file name to create :");
scanf("%s",fName);
/*creating (open) a file, in “w”: write mode*/
fp=fopen(fName,"w");
/*check file created or not*/
if(fp==NULL)
{
printf("File does not created!!!");
exit(0); /*exit from program*/
}
printf("File created successfully.");
return 0;
}
Output
Run 1:
Enter file name to create : file1.txt
File created successfully.
Run 2:
Enter file name to create : d:/file1.txt
File created successfully.
“file will be created in d: drive”.
Run 3:
Run 1:
Enter file name to create : h:/file1.txt
File does not created!!!
Program:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer