can you use an array fro the label in switch case

need to compare a received phone number callerIDbuffer to phone numbers hardcoded and change a variable reply from 0 to 1

tried code below and got switch quantity not integer and other errors. All the examples I have seen the case is either one letter or number not a string.

I know I can do it with if then else statemnts if it can be done but would like to know if only one letter or number can be used in the label of a case statement.

#include <SoftwareSerial.h>
#include "Adafruit_FONA.h"

#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

char callerIDbuffer[]="+12222222222";
char phone_numberMaritza[] = "+12222222222";
char phone_numberAnna[] = "+13333333333";
char phone_numberChip[] = "+14444444444";
int reply;

void setup() {
 // put your setup code here, to run once:
// Open serial communications and wait for port to open:

 while (!Serial) 
 Serial.begin(115200);
   ; // wait for serial port to connect. Needed for native USB port only
 
 Serial.begin(115200);
 Serial.println(F("FONA SMS caller ID test"));
 Serial.println(F("Initializing....(May take 3 seconds)"));

 // make it slow so its easy to read!
 fonaSerial->begin(4800);
 if (! fona.begin(*fonaSerial)) {
   Serial.println(F("Couldn't find FONA"));
   while(1);
 }
 Serial.println(F("FONA is OK"));
}         

void loop() {
Serial.println(F("comparing caller ID to phonenumber"));
switch (callerIDbuffer){
 case phone_numberMaritza:
       reply=1;
       break;
 case phone_numberAnna:
       reply=2;
       break;
 case phone_nmberChip:
       reply=3;
       break; }
    //if(strcmp(callerIDbuffer, phone_numberMaritza)==0){// works as string comparison
       
     //        reply = 1; // 
           Serial.print(F("reply after if=   ")); Serial.println(reply);}
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Please use code tags when posting code.

And this is like the 3th post about almost the same thing. You can't compare a array (which include c style strings) directly. That includes a switch().

you can use and array like this:

struct CallerInformation {
  char* callerName;
  char* callerNumber;
};

const CallerInformation caller[] = {
  {"Maritza", "+12222222222"},
  {"Anna", "+13333333333"},
  {"Chip", "+14444444444"},
};

void setup()
{
  Serial.begin(9600);
  char newCallerID[20] = "+14444444444";
  Serial.print("New Call from: ");
  switch (getCallerName(newCallerID))
  {
    case 0:
      Serial.println("Maritza");
      break;
    case 1:
      Serial.println("Anna");
      break;
    case 2:
      Serial.println("Chip");
      break;
    default:
      Serial.println("UNKNOWN");
      break;
  }
}

void loop()
{

}

int getCallerName(const char* number)
{
  for (int i = 0; i < sizeof(caller) / sizeof(caller[0]); i++)
  {
    if (strcmp(caller[i].callerNumber, number) == 0)
    {
      return i;
    }
  }
  return -1;
}

The general rule is that cases must be compile time constants so the compiler can build a jump table if it wants. There is a way to use variable cases, it is called an if/else statement.

I apologize im new and don't have a clue what code tags are can someone explain. sorry

They are the little brackets to the left of the text formatting buttons. (If you hover it says "code") The create HTML tags that let your code be shown like in the modified version of your first post above.

mromero:
I apologize im new and don't have a clue what code tags are can someone explain. sorry

You would have known if you had read the big fat sticky on top of each board called "How to use this forum". We can't make it any more easy then that...