C – File management

File Management

File Initialize object of the type

  • FILE // which contains all information necessary to control the stream

File Functions

  • Fopen() // Open a new file or open an existing file.
    • Syntax : FILE *fopen( const char * filename, const char * mode );
  • fclose() // close a file.
    • Syntax : int fclose( FILE *fp);
  • fputc() // Writing a file.
    • Syntax : int fputc( int c, FILE *fp );
  • fgetc() // Reading a file.
    • Syntax : int fgetc( FILE * fp );

Syntax

  • fopen(file_name”,"mode);

File Modes

Normal file handling

  • r – Open an existing file for Read purpose
  • wOpen an existing file for Write purpose
  • a – Open a file for writing in append mode. If file not exist, then create new file.
  • r+ – Open a file for both Read and Write
  • w+ – Opens a file for Read and Write. If a file is not existing it creates one, else if the file is existing it will be over written.
  • a+

Binary file handling

  • rb – Read (Binary file)
  • wb – write (Binary file)
  • ab – append (Binary file)
  • rb+
  • wb+
  • ab+
  • r+b – reading (Binary file)
  • w+b – (Binary file)
  • a+b – (Binary file)

 



Reference Link

  • https://www.tutorialspoint.com/cprogramming/c_file_io.htm

 

 


 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

if you have any queries call us +918300026060 or WhatsApp Dismiss

0

Your Cart

%d bloggers like this: