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

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



Joined: 26 Oct 2004
Posts: 13

View user's profile Send private message

printf
PostPosted: Thu May 19, 2005 4:56 pm     Reply with quote

I have the following problem using printf.
The device I am using is 18F252

Code example
Code:

long j;
j=244;
printf("%03lu",j);


The output I get is 4a0.

I have the problem with CCS 3.223 and 3.224

Bill
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Fri May 20, 2005 12:08 am     Reply with quote

The manual is available here:

http://www.ccsinfo.com/ccscmanual.zip

On page 136 they list the printf format options:

Quote:

Format:
The format takes the generic form %wt where w is
optional and may be 1-9 to specify how many characters
are to be outputted, or 01-09 to indicate leading zeros or
1.1 to 9.9 for floating point. t is the type and may be one
of the following:
C Character
S String or character
U Unsigned int
x Hex int (lower case output)
X Hex int (upper case output)
D Signed int
e Float in exp format
f Float
Lx Hex long int (lower case)
LX Hex long int (upper case)
lu unsigned decimal long
ld signed decimal long
% Just a %


So the code that should work is:

Code:
long j;
j=244;
printf("%LU",j);


(Even though this option isn't explicitly defined in the manual, I discovered it by trial and error.)

Good luck,

John
bill147



Joined: 26 Oct 2004
Posts: 13

View user's profile Send private message

PostPosted: Fri May 20, 2005 9:28 am     Reply with quote

My program had been working.

I have a function where I delare 2 long int and when
I added 2 more long int to this function was when the
problem started.

The problem even caused %lu to not work in other functions.

I have now made the additional 2 long int to be global
variables instead of a local variable. I still have the
original 2 long int in the function.

Well, %lu now works ok with printf.

Bill
bill147



Joined: 26 Oct 2004
Posts: 13

View user's profile Send private message

PostPosted: Mon May 23, 2005 9:53 am     Reply with quote

I have found that this problem must be a bug in the Compiler.

When the printf(%03lu) does not work right the compiler has assigned to printf memory from 0xfc to 0x104. It is strange because printf(%05lu) does work ok.

When I adust memory by using #locate, the compiler now assigns memory from 0x7c to 0x84 to printf and the function works ok.

Bill
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