Conversion string to int

Hi everyone can somebody help me?

I am using a serial communication with arduino and i am sending a string 112 or 12, but i cant convert it to integer.How can i convert to integer

How you convert a string to an integer depends on whether you mean string (as in NULL-terminated array of characters) or String (as in class instance). You're lack of proper capitalization in your post makes this unclear.

Whether you have either one, or just a set of characters that you read from the serial port one at a time isn't clear from the code you posted - hint, hint.

You're lack of proper capitalization

Oh, the irony. :)

Oh, the irony.

Multi-tasking is not always successful...

char* str = "123";
int i = atoi (str);
Serial.println(i);

Should be pointed out since you mentioned "serial communication" and "string" that Serial.read() only returns one byte at a time. So if by "send" you mean typing "112" into the serial monitor, you aren't sending a string. You are sending '1', then '1', then '2'.

Some simple serial servo code that captures a string number sent from the serial monitor and converts the string number into an integer for use in conrolling a servo.

// zoomkat 10-4-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// for IDE 0019 and later
// Powering a servo from the arduino usually DOES NOT WORK.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(2000); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control 
  Serial.println("servo-test-21"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(1);  
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    } 
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    int n;
    char carray[6]; //converting string to number
    readString.toCharArray(carray, sizeof(carray));
    n = atoi(carray); 
    myservo.writeMicroseconds(n); // for microseconds
    //myservo.write(n); //for degees 0-180
    readString="";
  } 
}

thank you guys for your help