How to write a c program fread() library function in c programming ?
Solution:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a[5], i;
FILE *fp;
if((fp = fopen("input.txt", "rb")) == NULL)
{
printf("Error opening file.\n");
exit(1);
}
if(fread(a, sizeof a, 1, fp) != 1)
{
printf("Error reading file\n");
exit(2);
}
fclose(fp);
for(i = 0; i < 5; i++)
printf("%d\n", a[i]);
return 0;
}