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 CCS Technical Support

Is this a bug or a feature of sprintf?

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



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Is this a bug or a feature of sprintf?
PostPosted: Thu Feb 28, 2008 8:47 pm     Reply with quote

Code:
int32 iADC;   // 24-bit value from an external ADC AD7718, MSByte is always 0
// read the ADC
sprintf(strOut, "%6LX", iADC);


Expected: 6 hexadecimal characters
Actual: 8 hexadecimal characters

PCWH 3.240, PIC18LF4520
_________________
Read the label, before opening a can of worms.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 28, 2008 9:57 pm     Reply with quote

See the test program shown below:

vs. 3.240 displays this:
Quote:
00123456


vs. 3.249 displays this:
Quote:
00123456


vs. 4.068 displays this:
Quote:
123456


Code:
#include <18F452.h>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000) 
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
   
//====================================
void main()
{
int32 iADC;   
char strOut[20];

iADC = 0x00123456;

sprintf(strOut, "%6LX", iADC);

printf(strOut);

while(1);     
}
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