Using the fread function: read size larger than readable

I have a question:

I am using fread to read a file.

typedef struct {
    int ID1;
    int ID2;
    char string[256];
} Reg;

Reg *A = (Reg*) malloc(sizeof(Reg)*size);

size = FILESIZE/sizeof(Reg);

fread (A, sizeof(Reg), size, FILEREAD);

Using a loop, call this call sequentially so that I read my entire file.

What happens when I get to the end of the file and I can’t read the “size” * sizeof (Reg), or if you can only read half that amount, what will happen to my array A. Will it be completed? Will the function return an error?

Knowing how the file was read through fread?

Edi1: Exactly, if the division is inaccurate, when I read the last bit of a smaller file size, which I will read things that are not in the file, I am interested with my changing the vector by the number of bytes that I can read or develop the dynamics better.

+3
source share
2

fread . , , .

fread , , , , .

: , , () , .

: , ( fread), . ", " .

+8

fread() , . fread(), , .

, EOF. feof() ond ferror(), , .

+1

All Articles