Q:

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

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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now