I have a program that reads a bin, and stores data in an array of structs.
My problem is that all the variables of the struct (int, long, unsigned int, char[8] etc) counted manually should add up to 60. A provided .bin file with only 1 entry (which is confirmed to be correct), also counts as 60 bytes using the following code:
fseek(file, 0, SEEK_END);
long int length = ftell(file);
fseek(record, 0, SEEK_SET);
HOWEVER, when I'm assigning space, I'm using a printf statement to debug:
struct Data *entries = malloc(length); // length is 60 from above code
printf("%d entries of size %ld", count, sizeof(struct Data)); // count is number of entries
// RESULT IN CONSOLE IS "1 entries of size 80"
So obviously, there's an extra 20 bytes when using sizeof(x). Why?
Also if that's the case, how DO I go about allocating the appropriate space, reading from a .bin file, if I don't know how many entries there are?
Thanks!
EDIT: This is the struct (mine):
struct Data{
    unsigned int creator;
    unsigned short fish;
    short vacation;
    char existence[8];
    short front;
    int bait;
    short peace;
    char night;
    char burst;
    unsigned long snow; 
    char finger;
    double idea;
    float goodbye;
    int stocking;
    char bell;
    double grandfather;
}
 
    