Problem with printf

Hi :slight_smile:

Why does this work:

display.printf("%d deg,", CalDirection, “%s”, dirbuch);

but this doesnt work:?

display.printf("%d deg, %s", CalDirection, dirbuch);

What are you sending the printf method to? i.e. what is the display object. How has printf been implemented?

Could you also show more of your code - specially how you have declared CalDirection and dirbuch?

It could be that the c-string has some odd character in it that stops the 2nd printf working.

You don’t really show of what type dirbuch is nore in what way the second version isn’t working.

Both is not very helpful :wink:

But I’ll dare a guess that dirbuch is of type String which is a non-trivial type which are not supported by printf() and its siblings.

Try this instead

 display.printf("%d deg, %s", CalDirection, (const char*)dirbuch);

BTW, I’m actually stumped that the first version works :flushed:

Since this looks like a display library that supplies a printf() function, it’s up to the library how that fucntion works. It might be called printf(), but that doesn’t mean it emulates standard functionality. What display library are you using? That would help diagnose the issue you’re seeing, and more importantly, lead you hopefully to documentation for that lib.

Or the display object is built off a class that inherits from class Print and reuse the implementation therein.