Q:

C program to create a text file using file handling, example of fopen, fclose

0

C program to create a text file using file handling, example of fopen, fclose

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

#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!!!

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now