Changing Char inside a Switch Case

Hey guys i know this is a easy question however my brain cant seem to work it out!! Basically i want to send a different text message based on the "Case" which is the keypad input, however im not sure how to declare the text message itself as its not working this way! the character array txtMsg is located within the SMSsend(); function!

switch (key)
    {
      case '*':
        digitalWrite(ledpin, LOW);
        break;
        
      case '#':
        digitalWrite(ledpin, HIGH);
        break;
        
       case '1':
          {
        char    txtMsg[200]='Hello1';
          
         SMSsend();
         break;
          }

          
         case '2':
         {
       char  txtMsg[200]='Hello2';
         SMSsend();
         break;
         }
         
          case '3':
         {
        char txtMsg[200]='Hello3';
         SMSsend();
         break;
         }

         case '4':
         {
         char txtMsg[200]='Hello4';
         SMSsend();
         break;
         }

Are you using the standard GSM library ? Study what the function in their example do...

Declare stuff needed

#include <GSM.h>

....

GSM gsmAccess; 
GSM_SMS sms;
boolean notConnected = true;

...

// in your setup connect things

while(notConnected)
  {
    if(gsmAccess.begin("PINNUMBER")==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

// in your various case statement

     sms.beginSMS("remoteNumber");
     sms.print("Hello1 - whatever you want to send");
     sms.endSMS();

Get rid of the {} in the cases 1,2,3,4 in the switch. They are not needed.

Get rid of the {} in the cases 1,2,3,4 in the switch. They are not needed.

It used to be the case (no pun intended) that without them you could not declare a variable within a case. Has that changed ?

UKHeliBob:
It used to be the case (no pun intended) that without them you could not declare a variable within a case. Has that changed ?

Not needed anymore should I have written for the eagle eyes :slight_smile: