Open the file in reading mode. If fopen function, open the file successfully, then using the fread function we can read the value of the variable.
#include <stdio.h>
int main()
{
//Variable to store read value
int data = 0;
//file pointer
FILE *fp = NULL;
//open the existing binary file
fp = fopen("aticleworld.dat", "rb");
if(fp == NULL)
{
printf("Error in opening the file\n");
exit(1);
}
//read variable value from file
fread(&data, sizeof(data), 1, fp);
fclose(fp);
return 0;
}
Open the file in reading mode. If fopen function, open the file successfully, then using the fread function we can read the value of the variable.
need an explanation for this answer? contact us directly to get an explanation for this answer