fread

The fread function in C is used to read data from a file. It takes four parameters: a pointer to the memory block where the data will be stored, the size of each element to be read, the number of elements to be read, and the file pointer.

Here is an example of how fread can be used:

#include <stdio.h>

int main() {
    FILE *file;
    int data[5];

    file = fopen("example.txt", "rb");
    if (file == NULL) {
        printf("Failed to open the file.\n");
        return 1;
    }

    fread(data, sizeof(int), 5, file);

    fclose(file);

    return 0;
}

In this example, the fread function is used to read five integers from the file "example.txt" into the data array. The sizeof(int) parameter specifies the size of each integer, and the 5 parameter specifies the number of integers to be read.

After the data is read, the file is closed using the fclose function.

Note that the file mode used in this example is "rb", which stands for "read binary". This mode is used when reading binary data from a file.

I hope this explanation helps! Let me know if you have any further questions.