BINARY FILES


A binary file is a file that uses all 8 bits of a byte for storing the information .It is the form which can be interpreted and understood by the computer.

The only difference between the text file and binary file is the data contain in text file can be recognized by the word processor while binary file data can’t be recognized by a word processor.

1.wb(write)

this opens a binary file in write mode.
SYNTAX:
fp=fopen(“data.dat”,”wb”);

2.rb(read)

this opens a binary file in read mode
SYNTAX:
fp=fopen(“data.dat”,”rb”);

3.ab(append)

this opens a binary file in a Append mode i.e. data can be added at the end of file.
SYNTAX:
fp=fopen(“data.dat”,”ab”);

4.r+b(read+write)

this mode opens preexisting File in read and write mode.
SYNTAX:
fp=fopen(“data.dat”,”r+b”);

5.w+b(write+read)

this mode creates a new file for reading and writing in Binary mode.
SYNTAX:
fp=fopen(“data.dat”,”w+b”);

6.a+b(append+write)

this mode opens a file in append mode i.e. data can be written at the end of file.
SYNTAX:
fp=fopen(“data.dat”,”a+b”);

STREAMS

A Stream refers to the characters read or written to a program. The streams are designed to allow the user to access the files efficiently .A stream is a file or physical device like keyboard, printer and monitor.

The FILE object contains all information about stream like current position, pointer to any buffer, error and EOF(end of file).

C supports a number of functions that have the ability to perform the basic file operations which includes

  1. naming a file
  2. opening a file
  3. reading data from a file
  4. writing data into a file
  5. closing a file
Copyright © 2018-2020 TutorialToUs. All rights reserved.