Parsing Integers from Serial Input

So, I'm new to programming and I'm having trouble with parsing data from the input I'm entering into the serial monitor. I want to input 4 numbers (either 1s or 0s) and assign each number to one variable in the code.

Pseudocode:

Input into Serial Monitor: 1101
Var1 = 1
Var2 = 1
Var3 = 0
Var4 = 1

Also, what if I'm inputting 12 numbers into the serial monitor and I want to assign the first 3 to Var1, second 3 to Var2, and so on?

I am asking this because I'm trying to control a set of 8 motors from the input data. Eventually I want to have the data sent from 4 pressure sensors, which will then control the 8 motors. But I don't have the pressure transducers yet, so I'm using the serial monitor to make sure I know how to program it when I get them.

Can someone please help?

I'm using a MEGA if that makes any difference.

Thanks

BackBraceBoy:
Can someone please help?

using a delimiter is key…

example message to input to serial monitor (using NewLine when you enter the string):

32;45;-63;89
const size_t MAX_MESSAGE_LENGTH = 32;

int var[4];

void setup() 
{
  Serial.begin(9600);
  Serial.println("let's go!");
}

void loop() 
{
  if(const char* newMessage = checkForNewMessage(Serial, '\n'))
  {
    Serial.println(newMessage);
    if (strlen(newMessage) == 0)
      Serial.println("*");
    char mssg[strlen(newMessage+1)];
    strcpy(mssg, newMessage);
    var[0] = atoi(strtok(mssg, ";"));
    var[1] = atoi(strtok(NULL, ";"));
    var[2] = atoi(strtok(NULL, ";"));
    var[3] = atoi(strtok(NULL, ";"));
    for (int i = 0; i < 4; i++)
    {
      Serial.println(var[i]);
    } 
  }
}

const char* checkForNewMessage(Stream& stream, const char endMarker)
{
  static char incomingMessage[MAX_MESSAGE_LENGTH] = "";
  static byte idx = 0;
  if(stream.available())
  {
    incomingMessage[idx] = stream.read();
    if(incomingMessage[idx] == endMarker)
    {
      incomingMessage[idx] = '\0';
      idx = 0;
      return incomingMessage;
    }
    else
    {
      idx++;
      if(idx > MAX_MESSAGE_LENGTH - 1)
      {
        //stream.print(F("{\"error\":\"message too long\"}\n"));  //you can send an error to sender here
        idx = 0;
        incomingMessage[idx] = '\0';
      }
    }
  }
  return NULL;
}

for a more general tutorial read this one: Serial Input Basics

You will also need to know about the key c-string functions from stdlib.h and string.h

Thanks, BulldogLowell. That worked.