CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

printf can handle only two hex digits?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Chen
Guest







printf can handle only two hex digits?
PostPosted: Fri Feb 07, 2003 9:28 am     Reply with quote

unsigned int16 i=0x5678;
char string [20];
byte stringptr=0;
tostring(char c){
if (c=='\f')
stringptr=0;
else
string[stringptr++]=c;
string[stringptr]=0;
}

....

printf(tostring, "\f\%4X", i);

----> string = "0078" instead of "5678"!
___________________________
This message was ported from CCS's old forum
Original Post ID: 11388
Hans Wedemeyer
Guest







Re: printf can handle only two hex digits?
PostPosted: Fri Feb 07, 2003 9:48 am     Reply with quote

You need to tell printf()it is a long..
like this

:=unsigned int16 i=0x5678;
:=printf(tostring, "\f\%4LX", i);
___________________________
This message was ported from CCS's old forum
Original Post ID: 11390
Chen
Guest







wow,
PostPosted: Fri Feb 07, 2003 10:16 am     Reply with quote

a 16-bit integer is already a long!

Thanks

:=You need to tell printf()it is a long..
:=like this
:=
:=:=unsigned int16 i=0x5678;
:=:=printf(tostring, "\f\%4LX", i);
___________________________
This message was ported from CCS's old forum
Original Post ID: 11393
R.J.Hamlett
Guest







Re: wow,
PostPosted: Fri Feb 07, 2003 10:50 am     Reply with quote

:=a 16-bit integer is already a long!
:=
:=Thanks
Yes, but _printf_ is designed to accept the default short integer by standard. If you are passing it a long, it requires the 'L' format (this works for both 16bit and 32bit 'longs).

Best Wishes

:=:=You need to tell printf()it is a long..
:=:=like this
:=:=
:=:=:=unsigned int16 i=0x5678;
:=:=:=printf(tostring, "\f\%4LX", i);
___________________________
This message was ported from CCS's old forum
Original Post ID: 11394
Sherpa Doug
Guest







Re: wow,
PostPosted: Fri Feb 07, 2003 11:27 am     Reply with quote

:=a 16-bit integer is already a long!
:=
:=Thanks
:=

Check out the definition of a short.
;-)

___________________________
This message was ported from CCS's old forum
Original Post ID: 11397
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group