hello,
I have a quick doubt, do you know a better way to make this in one line:
send_command(String("#") + String(cnt_pic));
to me this looks a little bit ugly
desired output:
#1
hello,
I have a quick doubt, do you know a better way to make this in one line:
send_command(String("#") + String(cnt_pic));
to me this looks a little bit ugly
desired output:
#1
Why does it have to be in one line?
no special reason, I was trying to make it and this was the only method i found, then i thought that maybe i was making something dummy
then i thought that maybe i was making something dummy
...by using the String class?
Good call.
ahahahah
If you can suggest me one way to do it inline with char[] I would be more than happy to avoit it
unfortunately i think that the only way would be with memcopy or printf
Why "unfortunately"?
(sp."sprintf". Or "itoa")
as far as i know sprintf takes a lot of resources, isn't it?
if i use the other method, right now i can only think to this:
char c[10] = "#";
char i[3];
itoa(my_byte, i, 10);
strcat(c, i);
do you really think is better/faster/cleaner than using the String() class? Or do you see better methods?
aster94:
as far as i know sprintf takes a lot of resources, isn't it?if i use the other method, right now i can only think to this:
char c[10] = "#";
char i[3];
itoa(my_byte, i, 10);
strcat(c, i);
do you really think is better/faster/cleaner than using the String() class? Or do you see better methods?
No, I absolutely do not think String is the better method, and I also think your itoa method could be cleaned-up and shortened.
could you please show how? I don't see how to shorten it
This would be the only function in my code where i use the String class so i am happy if i can avoid it
You currently have four lines of code.
Get rid of two of them.
char c[10] = "#"; char i[3];
send_command(strcat(c,itoa(my_byte, i, 10)));
I guess that this is my best, could it be better?
Yes.
You have too many buffers.
I made a few try to remove one of the two char array but looks like i am not able
I suspect i can live without 'i' but if i do itoa(cnt_pic, NULL, 10) doesn't work
can you show how?
How about
char c[10] = "#";
itoa(cnt_pic, c + strlen (c), 10);
Good catch
Thanks for the inputs!