Q:

create a file using fopen in C

belongs to collection: File handling in C

0

create a file using fopen in C

All Answers

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

In the below code, I am creating a text file using the fopen() function.

#include <stdio.h>
#include <stdlib.h>
int main()
{
    FILE *fp = NULL;
    //create a text file
    fp  = fopen ("aticleworld.txt", "w");
    if(fp == NULL)
    {
        printf("File is not created\n");
        exit(1);
    }
    else
    {
        printf("File is created\n");
    }
    //close the file
    fclose(fp);
    return 0;
}

Output:

If fopen() create file successfully, the text file will be created in the same folder where you have saved your code. Like the below image.

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

total answers (1)

How to use fread in c... >>
<< Writing an array of structure in a file using the...