How can i store the serial received number?

Hello,

I would like to store number as like a=50 when i receive "50" from serial monitor.

How can i do that?

Thanks.

Like this?

int yourNumber= atoi(yourString);

kind regards,

Jos

Very basic character capture and number conversion example.

//zoomkat 7-30-10 serial servo test
//type servo position 0 to 180 in serial monitor
// 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.attach(9);
  Serial.println("servo-test"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the String readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured String 
    int n = readString.toInt();  //convert readString into a number
    myservo.write(n);
    readString="";
  } 
}

String readString;
...
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the String readString
delay(2); //slow looping to allow buffer to fill with next character
}

Honestly I think there is a better way of doing this.Using String Objects just for this purpose is to much overkill.
Why not char arrays?
They are more lite and more efficient for what the user wants to do.
Manipulating char arrays is one of the skills that every programmer should know.