Computer Science, asked by Anonymous, 1 year ago

write a C program to perform different file handling operations.............don't spam​

Answers

Answered by BrainlyTech
3

\textbf{ Here is a file handling code }

/ * Open, write and close a file : */

# include <stdio.h>

# include <string.h>

 

int main( )

{

   FILE *fp ;

   char data[50];

   // opening an existing file

   printf( "Opening the file test.c in write mode" ) ;

   fp = fopen("test.c", "w") ;

   if ( fp == NULL )

   {

       printf( "Could not open file test.c" ) ;

       return 1;

   }

   printf( "\n Enter some text from keyboard” \

            “ to write in the file test.c" ) ;

   // getting input from user

   while ( strlen ( gets( data ) ) > 0 )

   {

       // writing in the file

       fputs(data, fp) ;    

       fputs("\n", fp) ;

   }

   // closing the file

   printf("Closing the file test.c") ;

   fclose(fp) ;

   return 0;        

}

Similar questions