Q:

create a file using fopen 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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now