I have a code like below:
int a; char cc[8];
a=1;
sprintf(cc,"%03ld",a);---->version 1
then cc[2]='2'.
if I use sprintf(cc,"%03ld", (long)a); --->version 2
then cc[2]='1'. that is what I expect.
My CCS version is 3.3.81.6. Do you have to cast before using sprint ?
Thanks.
Xianju
Hi,
This could depend on the int and long representation of your target machine and compiler implementation.
Is sizeof(int)==sizeof(long) ?
Have you already tried "%03d" (without the 'l')?
Alberto has the right answer here. Note that even if "int" and "long" have the same representation, a program which passes "int" to printf where a "long" is expected is not a strictly conforming program.