Spark firmware basic question - how to convert from int to char*?

A basic question - is there string.c_str() or StringPrintf()?

I see examples like String stringOne = String(‘a’); Can I write it as

String stringOne(‘a’); as in c++?

Is spark language a subset of C++? or it is totally different?

It’s the same language as is used on the Arduino, which is C with lots of bells and whistles on top. For the String object, take a look at Arduino’s String Object documentation. Post back if we need to dig deeper!

Hi @mwei1us

In addition to the Arduino String object class, you have char* available as well. That means the sprintf() is there as is itoa() etc. although one of those atoi() itoa() needed an extern to work. The memory management on the core is rudimentary, so I would not go nuts creating and destroying a lot of temporary String objects.

@BDub posted an itoa fix a while back in this thread. It didn’t seem to work for me, so I just used the String object instead.

Yes, that’s the one. That function lives in core-firmware/src/spark_wiring_string.cpp as a helper for the String class, but with the extern, you can use it too. There is an unsigned utoa() as well.