View previous topic :: View next topic |
Author |
Message |
bill147
Joined: 26 Oct 2004 Posts: 13
|
printf |
Posted: Thu May 19, 2005 4:56 pm |
|
|
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
|
|
Posted: Fri May 20, 2005 12:08 am |
|
|
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
|
|
Posted: Fri May 20, 2005 9:28 am |
|
|
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
|
|
Posted: Mon May 23, 2005 9:53 am |
|
|
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 |
|
|
|