How to use the atoi() function?

Hi.. How do I use the atoi() function to convert a String such as my_string = "123" to an integer? I tried atoi(my_string) but I get the following error

"cannot convert String to const char for argument '1' to int atoi(const *char)...

Post your whole code?

But just a tip - atoi works with char* strings, not the String class.

You need to convert your String object to a Character Array.

http://arduino.cc/en/Reference/StringToCharArray

Thanks James.. that's what I needed. Could you show my a code example? The documentation page doesn't have any.. I'm confused about what it means by "the supplied buffer".

  char buf[my_string.length()+1];
  my_string.toCharArray(buf, my_string.length()+1);

Need to add one since the string is null terminated.

Thanks a lot..

With the curent IDEs you should be able to use the below:

int value = my_string.toInt();