#include <iostream>
#include <cstdlib>
#include <cstring>

int main() {

    char input[] = "CMD:ADD,X=10;CMD:ADD,X=60;CMD:ADD,X=30;CMD:ADD,X=80;CMD:ADD,X=90";

    char * cmd = strtok(input, ";");

    int output[3] = {0};

    int writeIndex = 0;
    
    while(cmd != NULL) 
    {
        char * xPtr = strstr(cmd, "X="); 

        if(xPtr != NULL) 
        {
            int value = atoi(xPtr+2);

            if(value >= 50) 
            {
                if(writeIndex < 3) 
                {
                    output[writeIndex++] = value;
                }
                else 
                {
                    output[0] = output[1];
                    output[1] = output[2];
                    output[2] = value;
                }
            }
        }
        
        cmd = strtok(NULL, ";");
    }

    for(int i = 0; i<writeIndex; i++)
        printf("%d ",output[i]);
    printf("\ncount = %d",writeIndex);
    
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: