char array

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?

I wonder how convert char array to String or int type

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?

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.

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?

hi, :sunglasses: How do convert byte array to char array
[/i]

byte l[]={23,55,67}
char c[10];
void setup() {
 Serial.begin(9600);

}

void loop() {
 
  //???????
  
  
  
}

Why convert?
Why not simply cast?

Why do you want to?

This example and if you know how convert byte to char

Another cross-post? Pffft.

See reply #4

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);
}

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.