rati
1
i have char array,I would like to Count his Values sum.
char cha[]={1,2,3,5,5,6,7};
int m=0;
char l;
void setup() {
Serial.begin(9600);
}
void loop() {
for (int i=0;i<7;i++)
{
l=cha[i]+m;
m=l;
l=0;
Serial.print(m);
}
}[i][/i]
Very interesting. Is there a question there?
rati
3
I wonder how convert char array to String or int type
rati
4
I wonder how convert char array to String or int type
char cha[]={1,2,3,5,5,6,7};
int m=0;
char l;
void setup() {
Serial.begin(9600);
}
void loop() {
for (int i=0;i<7;i++)
{
}
}[i][/i]
I wonder how to stop you cross-posting? A ban, maybe?
C-F-K
6
A char array IS a string...
char test[] = {'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F'};
void setup() {
Serial.begin(115200);
Serial.println(test);
}
void loop() {
}
This will output the always funny DEADBEEF.
Don't forget that when you want to fill a char value you need to add the ' ''s. So instead of
char test = 0;
will fill it with a NULL character (Not the zero...), while
char test = '0';
will hold the actual zero.
Converting it to an int() is also not as hard:
Serial.println(test, DEC);
But that can only be done with a char, not a string.
system
7
A char array IS a string...
Oh dear, I don't quite know how to break this to you, but you're only partly correct.
Rati, you are a master of the X-Y Problem!
But yeay, no matter how you store a var it's still just a number. So to sum the array
char cha[]={1,2,3,5,5,6,7};
int sum = 0;
for(byte i = 0; i < 7; i++){
sum += cha[i];
}
But why on earth are you storing values as a char? What are you trying to do? Or is it some evil plan to take over the world?
rati
9
hi,
How do convert byte array to char array
[/i]
byte l[]={23,55,67}
char c[10];
void setup() {
Serial.begin(9600);
}
void loop() {
//???????
}
system
10
Why convert?
Why not simply cast?
rati
12
This example and if you know how convert byte to char
Another cross-post? Pffft.
Obviously I think Rati wants to convert {1,2,3} to "123".
void loop() {
char array[5] = {1,2,3,4,0};
for(int i=0; i<5; i++) { array[i] = array[i] + '0'; }
Serial.println(array);
}
system
16
It's not obvious at all what either you or rati thinks, and your code needs some work.
sonyhome:
Obviously I think Rati wants to convert {1,2,3} to "123".
The initial post read:
i have char array,I would like to Count his Values sum.
So that conclusion isn't particularly obvious to me.
indeed from the op, i guess i answered his second reply.
He has cross posted twice now (that is a total of three posts) so you could be forgiven for being confused.