Comparing data from parsed data

so i've read this tutorial: Serial Input Basics - updated - Introductory Tutorials - Arduino Forum
and i have several questions about it.

when using the example number five,

const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];

char messageFromPC[numChars] = {0};
int integerFromPC = 0;
float floatFromPC = 0.0;

boolean newData = false;

//============

void setup() {
    Serial.begin(9600);
}

//============

void loop() {
    recvWithStartEndMarkers();
    if (newData == true) {
        strcpy(tempChars, receivedChars);
        parseData();
        //showParsedData();

        if(messageFromPC == 1){showParsedData();}
        newData = false;
    }
}

//============

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;

    while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0';
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

//============

void parseData() {

    char * strtokIndx;

    strtokIndx = strtok(tempChars,","); 
    strcpy(messageFromPC, strtokIndx);
 
    strtokIndx = strtok(NULL, ",");
    integerFromPC = atoi(strtokIndx); 

    strtokIndx = strtok(NULL, ",");
    floatFromPC = atof(strtokIndx);

}

//============

void showParsedData() {
    //Serial.print("Message ");
    Serial.println(messageFromPC);
    //Serial.print("Integer ");
    //Serial.println(integerFromPC);
    //Serial.print("Float ");
    //Serial.println(floatFromPC);
}

i want to compare the data from "receivedDataFromPC" but cannot get any results from the if statement from inside the void loop. but when comparing the data from "integerFromPC" it gets a result. one more thing when entering more than 4 or five data for the integerFromPC it gets negative, why is that? im planning on using this for my mini-project for controlling an led strip wirelessly through bluetooth. thanks!

i want to compare the data from "receivedDataFromPC" but cannot get any results from the if statement from inside the void loop

messageFromPC is a string so you cannot use == to compare for equality. Use the strcmp() function. And you must compare string to string, not string to integer like in:

 if(messageFromPC == 1) // his will not work

but when comparing the data from "integerFromPC" it gets a result. one more thing when entering more than 4 or five data for the integerFromPC it gets negative, why is that?

integerFromPC is an int data type. The int data type holds numbers from -32768 to 32767. Numbers outside that range will overflow. See Arduino data types to see the ranges for different data types.

groundFungus:
messageFromPC is a string so you cannot use == to compare for equality. Use the strcmp() function. And you must compare string to string, not string to integer like in:

If i'm correct, doing that(strcmp) will require to store all the supposedly compared string into a variable. Is there a simple way of doing this when comparing more than 2 string?

Can you give an example of what you mean?

groundFungus:
Can you give an example of what you mean?

here's the code so far:

#include <FastLED.h>
#define NUM_LEDS 30
#define DATA_PIN 5

CRGB leds[NUM_LEDS];

const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];

//temporary
char messageFromPC[numChars] = {0};
int integerFromPC = 0;
float floatFromPC = 0.0;

boolean newData = false;

void setup() {
    Serial.begin(9600);
    LEDS.addLeds<WS2811,DATA_PIN,GRB>(leds,NUM_LEDS);
    //LEDS.setBrightness(255);
}

void loop() {
    recvWithStartEndMarkers();
    
    if (newData == true) {
       strcpy(tempChars, receivedChars);
       parseData();
       //showNewData();
       newData = false;
       }

    switch(messageFromPC){
        case 'a':
          //call a LED effect function here
          break;
  
        case 'b':
          //call a LED effect function here
          break; 
      
    }
    
    
}

/////////////////////////////////////////////////////////////////////////////

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;
 
    while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0';
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

/////////////////////////////////////////////////////////////////////////////

void parseData() {

    char * strtokIndx;

    strtokIndx = strtok(tempChars,",");
    strcpy(messageFromPC, strtokIndx);
 
    strtokIndx = strtok(NULL, ",");
    integerFromPC = atoi(strtokIndx);

    strtokIndx = strtok(NULL, ",");
    floatFromPC = atof(strtokIndx);
}

//tester

void showNewData() {
        Serial.print("Message ");
        Serial.println(messageFromPC);
        Serial.print("Integer ");
        Serial.println(integerFromPC);
        Serial.print("Float ");
        Serial.println(floatFromPC);
}

///////////////////////////
//All LED effect functions here
///////////////////////////

i realized i could just use switch case in void loop since i read that i could use a string without setting up all the compared data inside a variable, but it gave me an error of "switch quantity not an integer". so i think im back at using strcmp

switch(messageFromPC){

That will not work as messageFromPC is a string.
If the argument to the switch were a single character that would work:

switch(messageFromPC[0]) {  // for instance

groundFungus:

switch(messageFromPC[0]) {  // for instance

thanks! it works the way that im expecting, does putting the 0 at end of it makes it so that switch case will only read a single 'char' character? can you please tell me how it works?

I refer you to the Language Reference, particularly the Array reference.

An array is a group of items of the same data type. Each item (element) has a number (starting at 0) denoting its position in the array. The number is called the array index. The notation for picking a particular item from the array is the index enclosed in square brackets. The expression: array[0] refers to the first element of the array.

A string (note small 's') is a special kind of array. A string is a null terminated character array which means that the array ends with a '\0'. An array of characters that does not end with a '\0' is just an array, not a string.

Here is a page that shows the functions available for working with strings (concatenation, search, compare, ...)

groundFungus:
I refer you to the Language Reference, particularly the Array reference.

An array is a group of items of the same data type. Each item (element) has a number (starting at 0) denoting its position in the array. The number is called the array index. The notation for picking a particular item from the array is the index enclosed in square brackets. The expression: array[0] refers to the first element of the array.

A string (note small 's') is a special kind of array. A string is a null terminated character array which means that the array ends with a '\0'. An array of characters that does not end with a '\0' is just an array, not a string.

Here is a page that shows the functions available for working with strings (concatenation, search, compare, ...)

thanks for the info! i'll make that as a reference