Q:

C Program to read an array from the file using the fread

belongs to collection: File handling in C

0

Reading an array from the file using the fread

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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;
}

Output:

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Reading an array of structure using fread in C... >>
<< C program to read a variable from a file using the...