problem with printf()

Hello,
I want to ask a little bit help.
I want to use the printf instruction with the Noice debugger.

I can printf char or float fine but when I try to printf int or long I get a totally different numbers throu the serial port.

eg. WORKS
void main (void)
{
unsigned char f;
for (f=0;f<=255;++f)
printf( %bu \n",f);
}

but DOESN'T WORK

void main (void)
{
unsigned int f;
for (f=0;f<=255;++f)
printf( %u \n",f);
}
Thanks for any advice
Cheer George

Parents
  • I haven't used that fuction very often yet, but when I was using it, I have noticed, that you should be very accurate with the types of the arguments. It is always helpful to cast the parameter. In that example that doesn't work, you might want to try to cast f.

    void main (void)
    {
    unsigned int f;
    for (f=0;f<=255;++f)
    printf( %u \n", (unsigned int)f );
    }
    

Reply
  • I haven't used that fuction very often yet, but when I was using it, I have noticed, that you should be very accurate with the types of the arguments. It is always helpful to cast the parameter. In that example that doesn't work, you might want to try to cast f.

    void main (void)
    {
    unsigned int f;
    for (f=0;f<=255;++f)
    printf( %u \n", (unsigned int)f );
    }
    

Children
More questions in this forum