convert string serial data to char array and compare particular char

In this, i have tried to compare input[1] char but it does not print 'in' , even char 'm' at array input[1]. Anybody please tell me what modification I need to be done to compare particular char in a string.

char m;
String  input ;
void setup()
{
 Serial.begin(1200);
 
}
void loop() {

 input= " " ;



    while(Serial.available() > 0) { 
      
    
    for (int i=0; i < 5; i++) {
      input[i] = (char)Serial.read(); // Read the characters into an array
    }

 Serial.print(input);
if(input[1]=='m'){Serial.print("in");}

 
 }}

A string IS a char array, so no conversion is needed. Of course, you are NOT using strings. You are pissing away resources on String, which are NOT the saMe ThInG.

    while(Serial.available() > 0) {
     
   
    for (int i=0; i < 5; i++) {
      input[i] = (char)Serial.read(); // Read the characters into an array
    }

When there is one character in the buffer, it is NOT OK to read 5.

input is NOT an array, so using array notation is WRONG!

Why would the second character in the stream of data be m?

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example.

...R

@PaulS

Why would the second character in the stream of data be M?

In my project, I get command ((from 1 to 100)M) or ((from 1 to 100)F) from my windows application.

For example: when my windows application send serial data "3M" to arduino, I need to send serial output "in".

when my windows application send serial data "3F" to arduino, I need to send serial output "on".

Because of that only I compare second character, to differentiate different inputs.

thanks

At 1200 baud, it takes about 10ms for a character to arrive. Your Arduino finds the first character at time T but the second at time T + 10 ms. So your while loop will only iterate once.

Read Robin2's thread to get ideas how to collect the serial data first before processing it

It makes no sense to send "3M" or "30M" or "125T". It makes sense to send "M3" or "M30" or "T125". Parsing will be a whole lot easier if you don't have to guess where the letter is.