Semester : S1 and S2
Subject : Computer Programming
Year : 2017
Term : DECEMBER
Branch : BIOTECHNOLOGY
Scheme : 2015 Full Time
Course Code : CS 100
Page:42
fclose(fp);
}
Reading and Writing in a Binary File
A Binary file is similar to the text file, but it contains only large numerical
data. The Opening modes are mentioned in the table for opening modes
fread() and fwrite() functions are used to read and write is a binary file.
above.
fwrite(data-element-to-be-
written,
size_of_elements
number_of_elem
ents, pointer-tofile);
fread() is also used in the same way, with the same arguments like fwrite()
function. Below mentioned is a simple example of writing into a binary file
const char *mytext = "The quick brown
fox jumps over the lazy dog"; FILE *bfp=
fopen("test.txt", "wb");
if (bfp) {
fwrite(mytext,
sizeof(char),
strlen(mytext), bfp) ;
fclose(bfp) ;