Dear all,
I developed the following program:
void parsebytes(unsi gned char* data);
struct info
{
unsigned char day;
unsigned char month;
short year;
};
struct info info1;
struct info info2;
int
main(int argc, char *argv[])
{
info1.day=12;
info1.month=8;
info1.year=2007 ;
parsebytes((uns igned char*)&info1);
system("PAUSE") ;
return EXIT_SUCCESS;
}
void parsebytes(unsi gned char* data)
{
printf("day is %d\n", data[0]);
printf("month is %d\n", data[1]);
printf("year is %d\n", ((data[2] << 8) | data[3]));
}
The above program gives proper value of 12,8 for day and month.But
year value I always get junk.What should be done to correct this and
where have I gone wrong?
Looking farward for your replies and advanced thanks,
Regards,
s.subbarayan
I developed the following program:
void parsebytes(unsi gned char* data);
struct info
{
unsigned char day;
unsigned char month;
short year;
};
struct info info1;
struct info info2;
int
main(int argc, char *argv[])
{
info1.day=12;
info1.month=8;
info1.year=2007 ;
parsebytes((uns igned char*)&info1);
system("PAUSE") ;
return EXIT_SUCCESS;
}
void parsebytes(unsi gned char* data)
{
printf("day is %d\n", data[0]);
printf("month is %d\n", data[1]);
printf("year is %d\n", ((data[2] << 8) | data[3]));
}
The above program gives proper value of 12,8 for day and month.But
year value I always get junk.What should be done to correct this and
where have I gone wrong?
Looking farward for your replies and advanced thanks,
Regards,
s.subbarayan
Comment