Help with character array

Hi everyone, I am trying to write a simple code to turn on an LED if a serial string “OK” is received via the UART pins. This is what I have but it doesn’t work properly.

const byte numChars = 32;
int ndx =0;
int find=0;
int j; // "for" loop counter
int led = 13; // int to track the char pos in the array
char recvChars[numChars];	// an array to store the received data
void recvData();

void setup() {
 pinMode(led, OUTPUT); 
	Serial.begin(9600);
delay(200);
    
}

void loop() {
recvData();
}
//input a string of data then press send.
void recvData() {

if(Serial.available() > 0) {
recvChars[ndx] = Serial.read();//Once the serial data in the buffer is read, the buffer goes empty.
ndx++;
if (ndx == numChars) 
ndx = 0;
}
while(recvChars[find]!='O'){find++;}
if((recvChars[find]=='O')&&(recvChars[find+1]=='K')){
for(int j=0; j<10; j++){
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);        
}
find=0;
}

}

Can anyone assist?

moderator edit: Code tags. Always code tags.

Imagine the first character you enter at the keyboard is a space. What does your first while loop do?

Before you post your code within code tags and while your code is still in the source window of the IDE, use Ctrl-T to reformat your code into a common C style. It makes it easier for us to read. You should also read the posts by Nick Gammon at the top of this Forum before making additional posts. It will likely increase the number of responses you get.

As you read each character/byte available at the serial port, you need to looking for the letter O. Once you have it, you need to see check that the very next letter is K.

Anyway, it looks like your sketch is looking for zero 0 and not the capital letter O.

Also, what happens if they enter a 'k' or an 'o'? That's easily solved with:

recvChars[ndx] = toupper(Serial.read());