438 Programming and Data Structures
«d .t (l)»
}
clrscr ();
printf("n Enter Player Name, Age & Runs Scored n");
printf ("= = = = ===== ==== === = ========== W ');
scpnfVAs %d %d”&np.player, &emp.age,&emp.runs);
fwrite (&entptfzeof(emp),l,fp);
fcloseffp);
if (tfPrfopenCrecord.dat", ‘Y '))= = N U L L )
i
printf ( “
Errerin openingfile’’);
exiHl);
i
printf ("n Record Entered is n");
fread (&emp,sizeof(entp),l,fp);
printf ( “
%s %d %d", emp.player, emp.age, emp.runs);
fcloseffp);
}
OUTPUT;
Enter Player Name, Age & Runs Scored
Sachin 2510000
Record Entered is
Sachin 25 10000
Explanation In the above program user writes the information of the player using fw ri te function.
The entire record of player which is containing information given in the structure is written first using
fwrite () function.
Similarly, the information written in the file can be read by using fread () function. Thus, the
program reads entire data file with single fread () and writes the data with single fw rite () function.
These two functions are efficiently used for handling I/O files in comparison to f scanf () and
fprintf ().
13.19 Write a program to write a block of structure elements to the given file using fwriteO
function. User should press' Y' to continue and 'N ' for termination.
# include <atdio.h>
# include <conio.h>
# include <procese.h>
void main ()
{