[Solved] if (indata[0] == ’10’) does not work [closed]


I see a couple of issues.

First, use the if..then..else construct or a switch for the several if..then statements.

And, when you do a comparison to a char 10 is two char values so a simple == won’t work.

You could convert it to an integer first, using atoi and then do a comparison, or you can look at if (inData[0] == '1' && inData[1] == '0') would do what you want.

UPDATE:

I would ensure that each part of inData is set to zero first, not ‘0’.

Then use a switch, such as something like this:

switch(inData[0]) {
  case '1':
    switch(inData[1]) {
       case 0:
         // This would be '1'
         break;
       case '0':
         // This will be 10
         break;
    }
    break;
  case '2':
     break;
}

I haven’t tested this code, just use as an example.

7

solved if (indata[0] == ’10’) does not work [closed]