Help with reading numbers through serial

so i have a project in which i need to read numbers from the serial input and then parse them and feed them to 2 servo motors . I have a big file of commands which is way too big to store in the internal memory of the arduino . the commands are basically numbers (degrees) , separated by a space . i use a c++ program to feed the numbers to the serial port 1 by 1 .

void loop() {
  //If any input is detected in arduino

  if (  Serial.available() >1  ) {


    if (ctr ==1) {
    
      y = Serial.parseInt();
       Serial.print(("Y:"));

  w = true ;
    }
    if (ctr == 0) {
        digitalWrite(LED_BUILTIN, LOW); 
             if(w ){
                  servo1.write(x);
                   servo2.write(y);
                     w = false;
                   digitalWrite(LED_BUILTIN, HIGH); 
             }
        x = Serial.parseInt();
  

    }

    if(ctr== 0) ctr = 1 ;
    else if (ctr ) ctr = 0 ;

  }

}

this is the main code of the arduino. My problem is that it constantly reads junk values into the x and y variables , and my servos don't move. I'm pretty sure that the c++ program sends the right values (it sends c strings ) , it sends them very fast so that might be a problem . I guess my biggest mistake is not knowing in detail how the serial port works , and how to use it .

here is a snippet of what the command file looks like

49 36 47 37 46 38 45 39 45 40 45 41 44 42 44 43 44 44 44 45 44 46 44 47 44 48 44 49 45 50 45 51 46 52 47 53 48 54 50 55 52 56 72 57

Start simple. Make a very simple program that slowly sends data to the Arduino. On the Arduino side just read from the serial and print what you see, then build things up from there.

it sends them very fast

It sends them only as fast as permitted by the Baud rate you have selected for the serial port. What is that rate? Serial Input Basics

Hi, Try here first; Serial Basics

http://forum.arduino.cc/index.php?topic=396450.0

Tom.... :)

My approach: Read character, if digit store it in a char array, if space go ahead and parse the char array as int, clear the char array, and start reading again. Checks to make: 1) only store digits in the char array, 2) make sure your char array doesn't overflow (in case for whatever reason the spaces are not sent).