The below code reads 5 elements from the file and stores it in data (an integer array).
#include <stdio.h>
int main()
{
//Reading element of array
int data[10] = {0};
//file pointer
FILE *fp = NULL;
//open the existing binary file
fp = fopen("aticleworld.dat", "rb");
if(fp == NULL)
{
printf("Error in creating the file\n");
exit(1);
}
//Reads 5 element from the file and stores it in data.
fwrite(data, sizeof(data[0]),5, fp);
fclose(fp);
return 0;
}
The below code reads 5 elements from the file and stores it in data (an integer array).
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer