I have a binary file where I log the offset at which writes to other files occur and the data that is written at that offset. Now I define the structure of each log record as

struct log_record{
int offset;
char *data;
}
struct log_record t;

When I write the record into the file, I have the length of data that I write into the file and hence before assigning I allocate space as

t.data = (char*)malloc(sizeof(char)*strlen(buff));/*buf holds the data to be written*/

Now I have the length of the record I am writing into the file...But the issue is while reading. How do I allocate space against a structure that I read the record into and in the fread what should be the size of the record. Am a few confused.
Would be gratefull for help

You should avoid writing whole structures to disk and reading them back in again. You'll run into problems with different architectures and, as you've noticed, pointers and variable length data structures. Instead, marshal the data by hand on output and put it back together when you read it.

In your specific case, instead of writing a struct log_record, you want to write three things:

The offset (choose your size and byte order and stick to it).

The length of data (in the same format as above).

The actual bytes of data.

Then, when you're reading the data back in, read in the offset and rearrange its bytes to match the local byte order. Then read the length (in the same way as offset). Now you know how big the data is so you can allocate your memory and slurp it off the disk with a single call to fread.

Oh and don't cast the return value of malloc, there's no need for it and it can hide problems. Instead, just say this:

/* See above for how to figure out data_length. */
t.data = malloc(sizeof(char) * data_length);

It is not possible to write structs with variable sizes to a binary file, and then read them back again without any record of their size. You could either use a char array with a fixed size instead of a char pointer, or use a custom file format where you record the size of each element if you need them to be of variable length.

Since I didn't have anything better to do, I wrote a little program which I hope does what you are looking for. No error checking :)