embeddedartistry / arduino-printf

Add printf support to the Arduino SDK
MIT License
91 stars 15 forks source link

How to print a String #34

Closed oneandonlyonebutyou closed 2 years ago

oneandonlyonebutyou commented 2 years ago

I have a

String  s = "Hello" 

Serial.print(s); // works printf("%s\n",s). << Does not work :(

phillipjohnston commented 2 years ago

Sorry - I responded to you via email but it appears it did not post here.

printf only works with C strings (it is a C language function, not C++). If you have a String object, you can access that via the c_str member function:

printf("%s\n", s.c_str());