user3235701
user3235701

Reputation: 1

Using fread to read and want to use structures from a binary file in C

I have a binary file and i use this code to read it.

FILE * File;
long Size;
char * buffer;
size_t result;

File = fopen ( "STUD.bin" , "rb" );
fseek (File , 0 , SEEK_END);
Size = ftell (File);
rewind (File);
buffer = (char*) malloc (sizeof(char)*Size);
result = fread (buffer,1,Size,File);

Ii want to use those structures from the binary file. What code should i use for that?

Upvotes: 0

Views: 133

Answers (1)

Anirudh
Anirudh

Reputation: 385

Your question seems a little unclear. But if the case is that you have a structure in the binary file and want to read it then do the following

    struct example abc;
    fread(&abc,sizeof(abc),1,File);

Upvotes: 1

Related Questions