In line 14, three variables n, i and chars are declared of type int. After you compile and run this program, you can see a text file program. A file is nothing but space in a memory where data is stored.
Reading from a binary file Function fread also take 4 arguments similar to the fwrite function as above.
Number of items written to the file: 1 How it works: In linesa structure employee is declared which has four members namely name is an array of characters, designation is also an array of characters, age is of type int and salary is of type float.
The functions take four arguments: address of data to be written in the disk size of data to be written in the disk number of such type of data pointer to the file where you want to write.
Here we are writing the data of a single structure variable so fwrite will return 1. The file associated with the file pointer is then closed with the help of fclose function.
Notice that in line 34 fflush function is called to flush remove the newline character from the standard input which was entered while entering the number of records in line Different whence in fseek.
An easier way to get to the required data can be achieved using fseek. Otherwise, the program continues with the statement following the if statement. In line 52, fclose function is used to close the file.