Actions

EmSys

C - Explicit type conversion2

From EdWiki

Revision as of 06:51, 7 March 2012 by Jshankar (Talk | contribs) (1 revision)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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;
}