printf and a variable

15 Jul 2010 . Edited: 15 Jul 2010

A beginner's question for you.  I am using a serial instance called "pc":

Serial pc(USBTX, USBRX);

I can't seem to print out my actual variable values using the printf command.  For instance, if I have an unsigned integer variable "foo", then I want to print it out to the PC terminal:

pc.printf(foo);

But this gives me an error:

Argument of type "unsigned int" is incompatible with parameter of type "const char *"

I believe that several MBed examples use the printf statement like this to print out a variable to the terminal screen.  What am I doing wrong here?

15 Jul 2010 . Edited: 15 Jul 2010

Hi Richard,

Try pc.printf("some optional text %d",foo);

This should display the variable

25 Jul 2010

Thank you Martin, it worked!!

14 Jan 2012

Sorry for my nooby Question in terrible english ;-) but i'm owning the Mbed just since 3 Days...and even so long i need to use C and have some little problems with it ;-)) because it seems to be more different to the Arduino-IDE language i used before than i thought...

Shure, it is funny to just do this, but what is the reason for it to write some code in this way? In some codes written in C#/C++ i see a %d, some uses a %b, some a %z...I think that the % is defining the use of a variable and the char after % is just a placeholder for the variable, but could i use any Char after the %?

14 Jan 2012

ou will found responce for all your questions

http://www.cplusplus.com/reference/clibrary/cstdio/printf/

14 Jan 2012

Thank you, kevin....that is all i need... Great, i'm really confused that i don't had the idea to google the reference...normaly i'm not this kind of helpless :-/