Convert string to int

Hello,

I wish to convert string to int but i have lot of problems

Here you have my code :

#include <stdlib.h>

char recu[20]; 
String reponse; 
int i=0; 

void setup()
{
  Serial.begin(9600);
}


void loop()
{
   i=0;
   while ( Serial.available()>0 )      { 
       recu[i] = Serial.read(); 
       
       //Serial.println(recu[i]);
       if (recu[i]=='-')
       { 
         //On arrete le transfert et on met à zero la reception
          Serial.println("Fin de reception");
          Serial.println("Avant Suppression= "+ reponse);

          //On vide l'ancienne valeur
          reponse="";
          
       }
       else if (recu[i]=='+')
       { 
          Serial.println("Debut de reception"); 
       }
       else if (recu[i]=='*')
       { 
          Serial.println("Relance du transfert"); 
       }else
       {
         reponse += recu[i]; 
         i++;  
       }
   } 
   if (i>0)
   { 
      Serial.println(reponse); 
   }
}

//How can i do here to convert reponse to int value
i want to transform response = “123658” to i=123658

How can i do ?

I use arduino uno

thanks

I am deleting your other post if it is a duplicate of this one ...

I wish to convert string to int but i have lot of problems

I can imagine that you do, because you don’t have a string. You have a String, which is a completely different thing altogether.

The String class has a toInt() method that you could have found by looking at the documentation.

Some servo test code that has "int value = inString.toInt(); ".

// Serial Servo Tester 10/28/11
// Use the Serial Monitor to write a value from 0 to 180
// Set Serial Monitor line ending to Newline
// for writeMicroseconds, use values from  544 to 2400

#include <Servo.h> 

Servo myservo;  // create servo object to control a servo 
String inString;

void setup()
{
  Serial.begin(9600);
  myservo.attach(9);  //the pin for the servo control 
  Serial.println("Enter angle between 0 and 180 (values > 544 written as Microseconds)");  
}

void loop() {

  while (Serial.available()> 0) {
    int inChar = Serial.read();
    if (isDigit(inChar)) 
    {
      // if the incoming character is a digit, add it to the string
      inString += (char)inChar; 
    }
    else
    {
      // here on the first character that is not a digit   
      int value = inString.toInt(); 
      if(value >= 544)
      {
        Serial.print("writing Microseconds: ");
        Serial.println(value);
        myservo.writeMicroseconds(value);
      }
      else
      {   
        Serial.print("writing Angle: ");
        Serial.println(value);
        myservo.write(value);
      }
      // clear the string for new input:
      inString = "";   
    }
  }
}