Topic : Where is my string??

Forum : Ride IDE

Original Post
Post Information Post
January 29, 2010 - 8:28am
Guest

it seems i am the most stupid member on the forum..! getting these trivial issues..!

My latest issue is as trivial as earlier.

i have written down a code to replace the functionality sprintf.

void func1(void)
{
u8 sCRCBuff[13];
u32 iCRC;
...
//sprintf(sCRCBuff,"%lu",iCRC);
sprif(sCRCBuff,iCRC);
Display(sCRCBuff);
Display("\r\n");
...
}

void sprif(u8 *x,u32 i)
{
u8 y[11],*p;
y[11] = 0;
p = &y[10];

while(i > 0)
{
*p-- = i%10+0x30;
i /= 10;
}
strcpy(x,++p);
if(*x == '\0')
strcpy(x,"0");

//Display(x);
}

this function works in one project.

while in another project this function fails to return any value or gives me garbage value..!
this has baffled me for more that 3 days now!

if i replace my function with the sprintf i get proper value!

also if add the display function in the sprif fuction at the end as shown in comments,
the function works..!!

i have tried making that array as a global.! (just to cross check) but to no avail.

Difference between the two projects:
Same files have been included in both the projects.
only difference between the two projects is the linker script.
modification in the linker script is made to define the flash memory size.

the display function just puts a string on the serial port.

i am on verge of pulling out my hair!!
can anyone shed some light on the issue!

regards
p1

Replies
Post Information Post
+1
0
-1
January 29, 2010 - 9:02am
Raisonance Support Team

Hi Pavan,

There is a classical bug in your code:

    u8 y[11],*p;
    y[11] = 0;    // Error! ystarts as index 0!
    p = &y[10];   // Error again

Correct your code as follows:

    u8 y[11],*p;
    y[10] = 0;
    p = &y[9];

Then everything will come back in place...
Regards

+1
0
-1
January 29, 2010 - 9:09am
Raisonance Support Team

BTW,

Our printf is optimized in LOTS of ways. Generally speaking it will be very efficient in terms of both code size and speed of execution; it is Standard C standard; it is reentrant (usable from interrupts).

Use our printf instead of rewriting yours.

However, this is true for our compilers (8051, MicroPass, ST7/STM8). If you are using GCC for instance the printf size may get huge...

Regards,

+1
0
-1
January 29, 2010 - 9:25am
Guest

Thank Bruno..!!

i wonder how i overlooked that!

to give a excuse..!!
may be i didnt focus on this function at all and was searching for the bug somewhere else..!!

thank you