C program to write data into file.

Posted by Mangesh on March 31, 2018

/* C program to write data into file. */

Description :

We want to write the data into file using C language.

Program :

#include<stdio.h>
int main()
{
   char data[1000];
   FILE *fptr;
   fptr = fopen("filename.txt", "w");
   if(fptr == NULL)
   {
      printf("Error!");
   }
   else
   {   
     printf("Enter the data to write in file :\n");
     gets(data);
     fprintf(fptr,"%s", data);
     fclose(fptr);
   }
   return 0;
}


Output :

c program for write into file Executed and Tested in Turbo C 3.2

Written with from Mangesh.

Related Post
1 C program to read data from file.
2 C program to write data into file.
3 C program to delete the File.
Latest Post
1 shubhanshu
2 test
3 C program for Breadth First Search.
4 C program for Depth First Search(DFS).
5 C for circular queue using linked list.