Contact Learn C
Copy Program Share Program

Program 203:Writing into file

Program 203:
 
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 main ()
 {
    FILE *file;
    char s[100];
    file=fopen("file2.txt","w");

     if(file==NULL)
     {
      printf("File Not Found\n");
      exit(0);
     }
     else
     {
      printf("Enter lines to write in file\n");
      while(strlen(gets(s))>0)
      {
       fputs(s,file);
       fputs("\n",file);
      }
     }
    fclose(file);
 }
Explanation:

//Coming Soon...

Output:

Store both text file and program in same folder.Here I named text file as file2.txt 
Before Running Program




Running the Program

Writing into file




After Running the program



 

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide