4: Write a C program to (a)
Write an array of 8 elements to a file. (b)
Write a structure to a file. (c)
Read a structure from a file. Solution 4(a): #include #include void main( )
{
FILE *fp;
int a[8], i;
clrscr( );
if ((fp = fopen(“test.dat”, “wb”)) = =NULL)
{
printf(“\n Cannot open file”);
exit(1);
}
printf(“\n Enter 8 numbers:”);
for (i=0; i<8; i++)
scanf(“%d”, &a[i]);
fwrite(a, sizeof(a), 1, fp);
fclose(fp);
}