I am enhancing a program that runs on a piece of hardware designed by my company. I don't do a lot of C programming. To make a long story short, I can't print a value correctly.
My current code is:
sprintf(out, "%x\n", myStuct.lastPrinted[1]);
myStruct.lastPrinted is an array of byte. It is holding a date-time that should be properly displayed when printed in hex form.
When it is printed (one position at a time), I get this :
307 //year
707 //month
807 //day
1307 //hour
5207 //minute
3007 //second
This date would be July 8, 2003 13:52:30.
The "07" part varies with the date, but I've only seen "0"-something.
If I print it out like this:
sprintf( tempString, "%x/%x/%x %x:%x:%x\n", myStuct.lastPrinted[0],myStuct.lastPrinted[1],
myStuct.lastPrinted[2],myStuct.lastPrinted[3],
myStuct.lastPrinted[4],myStuct.lastPrinted[5]);
I would get: 307/813/5230 ff:ff:232
My suspicion is that it's pulling two bytes instead of just the one byte the value is stored in. I've been having a tough time trying to prove this, so I thought I'd ask.
What's the best way to solve this problem?
My current code is:
sprintf(out, "%x\n", myStuct.lastPrinted[1]);
myStruct.lastPrinted is an array of byte. It is holding a date-time that should be properly displayed when printed in hex form.
When it is printed (one position at a time), I get this :
307 //year
707 //month
807 //day
1307 //hour
5207 //minute
3007 //second
This date would be July 8, 2003 13:52:30.
The "07" part varies with the date, but I've only seen "0"-something.
If I print it out like this:
sprintf( tempString, "%x/%x/%x %x:%x:%x\n", myStuct.lastPrinted[0],myStuct.lastPrinted[1],
myStuct.lastPrinted[2],myStuct.lastPrinted[3],
myStuct.lastPrinted[4],myStuct.lastPrinted[5]);
I would get: 307/813/5230 ff:ff:232
My suspicion is that it's pulling two bytes instead of just the one byte the value is stored in. I've been having a tough time trying to prove this, so I thought I'd ask.
What's the best way to solve this problem?