The below code using the fread function reads the first 5 elements of structure array from the file and stores it in the structure array sAticleworldEmplInfo.
#include <stdio.h>
//structure
typedef struct
{
int id;
char fName[16];
char lName[16];
} s_employee;
int main()
{
//Array of structure variable
s_employee sAticleworldEmplInfo [10]= {0};
//file pointer
FILE *fp = NULL;
//open the existing file
fp = fopen("aticleworld.dat", "rb");
if(fp == NULL)
{
printf("Error in creating the file\n");
exit(1);
}
//Reads the five first element of the array of structure
fread(sAticleworldEmplInfo, sizeof(sAticleworldEmplInfo),5, fp);
fclose(fp);
return 0;
}
The below code using the fread function reads the first 5 elements of structure array from the file and stores it in the structure array sAticleworldEmplInfo.
need an explanation for this answer? contact us directly to get an explanation for this answer