So I\'m having a bit of an issue of not being able to properly read a binary file into my structure. The structure is this:
struct Student
{
char name[25];
A simple workaround is to pack your structure to 1 byte
using gcc
struct __attribute__((packed)) Student
{
char name[25];
int quiz1;
int quiz2;
int quiz3;
};
using msvc
#pragma pack(push, 1) //set padding to 1 byte, saves previous value
struct Student
{
char name[25];
int quiz1;
int quiz2;
int quiz3;
};
#pragma pack(pop) //restore previous pack value
EDIT : As user ahans states : pragma pack is supported by gcc since version 2.7.2.3 (released in 1997) so it seems safe to use pragma pack as the only packed notation if you are targetting msvc and gcc