Actions

EmSys

Difference between revisions of "C - Explicit type conversion2"

From EdWiki

m (1 revision)
 
m (1 revision imported: EdWiki -- Emsys pages from Shukra)
 
(No difference)

Latest revision as of 09:30, 23 June 2015

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