Actions

EmSys

C - Explicit type conversion2

From EdWiki

Explicit type conversion ...

struct tagEmployee {
    int staffcode;
    char name[20];
    char designation[20];
    float basicsalary;
    int department;
};
 
char cBuf[sizeof (struct tagEmployee) * 100];
 
main()
{
    struct tagEmployee* pe;
 
    pe = (struct tagEmployee*)malloc(sizeof(struct tagEmployee));
 
    // fill the data
    fwrite(pe, sizeof(struct tagEmployee), 1, fid);
 
    //
    fread( cBuf, sizeof (struct tagEmployee), 100, fid);
    pe = (struct tagEmployee*)cBuf;
}