atoi

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
User avatar
10der
Posts: 80
Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA

atoi

Post by 10der »

hello!

how to convert char* to int
standard c++ atoi function is not supported by z-uno core.

thanks!
User avatar
10der
Posts: 80
Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA

Re: atoi

Post by 10der »

(facepalm)

Code: Select all

int toInt(char* str) {

  int s = 1;
  int i = -1;
  int res = 0;

  if (str[0] == '-') {
    s = -1;
    i = 0;
  }

  while (str[++i] != '\0') { //iterate until the array end
    res = res * 10 + (str[i] - '0'); //generating the integer according to read parsed numbers.
  }

  res = res * s;
#ifdef DEBUG
  Serial.println(res);
#endif
  return res;
}

User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: atoi

Post by PoltoS »

We will add atoi in 2.0.9. It should already be in strings.h, but probably the prototype is not declared in headers. We will take care
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: atoi

Post by PoltoS »

milimilo
Posts: 8
Joined: 16 Jun 2017 23:12

Re: atoi

Post by milimilo »

Hello,

It seems that atoi/atol/atof are still not supported even in 2.1
I still have an error message.
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: atoi

Post by PoltoS »

It was tested to work. Lease send us more info to reproduce it
Post Reply