char array to int

Hi I have a project that receives data from a wishield. Most is working but I have a problem converting the char array to an integer value.

I think this is a C related issue and me not properly understanding the int() conversion method.

Any help is much appreciated

The code below illustrates the problem.

void setup(){
 Serial.begin(57600);
 char data[] = "128";
 int myint = int(data);
 Serial.println(data); // print "128"
 Serial.println(myint); // print 128
 Serial.println(myint++); // print 129
 
 /* 
 Results in serial monitor...
 128
 2290
 2290
 */

}

void loop(){}

Have look at "atoi".

What you're doing is converting a pointer to "char" (char*) to an integer.

Technically its a cast, not a conversion - the value of the pointer is being re-interpreted as if it was declared int, the value is not touched. Casting types like this is often confusing and leads to problems - and certainly casting pointers to and from integers is unlikely to be useful in an Arduino sketch.

atoi() etc are the way to go