This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

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
  • This is an old chestnut!

    It is very important that the argument types must match precisely the types specified in the format string.

    Read the section Problems Using the printf Routines in the C51 manual, and see the table of format characters in the description of printf.
    In particular, note that %d and %u are for ints; for chars you must:
    either use the b prefix;
    or cast your char to an int

Reply
  • This is an old chestnut!

    It is very important that the argument types must match precisely the types specified in the format string.

    Read the section Problems Using the printf Routines in the C51 manual, and see the table of format characters in the description of printf.
    In particular, note that %d and %u are for ints; for chars you must:
    either use the b prefix;
    or cast your char to an int

Children
No data