How to create a function that detects whether the user has entered ASCII or ASH?

I am in the process of creating a program which allows the user to enter either ASCII (text) or ASH and get a translation back. However, to do this I need to create a function which detects if the user has entered ASH or ASCII, so it can be translated accordingly. I have included the code I have written so far below. I just need some kind of template to go off for the function, I don't expect to receive an exact solution just a guideline or some general help, as I'm pretty stuck right now!

At the moment I have to call the function in the actual code to get the solution to display in the serial port, whereas eventually I want to let the user type in the text or ASH they want straight into the serial port, and get back their translation.

I have included a print screen of the output in the serial port, the first part saying hello has been translated from ASH to text and the second part says ash code in ASH characters.

Thanks in advance for any help offered!

char ASH_a[] = "*"; //global variables defined to match ASCII text with its ASH equivalent 
char ASH_b[] = "!!*";
char ASH_c[] = "!!@";
char ASH_d[] = "*!";
char ASH_e[] = "!";
char ASH_f[] = "!*!";
char ASH_g[] = "**";
char ASH_h[] = "!**";
char ASH_i[] = "!!";
char ASH_j[] = "*!!";
char ASH_k[] = "*@";
char ASH_l[] = "!*@";
char ASH_m[] = "!*";
char ASH_n[] = "!@";
char ASH_o[] = "@*";
char ASH_p[] = "!@!";
char ASH_q[] = "*!@";
char ASH_r[] = "!@*";
char ASH_s[] = "@!";
char ASH_t[] = "@";
char ASH_u[] = "@@";
char ASH_v[] = "**!";
char ASH_w[] = "***";
char ASH_x[] = "*@!";
char ASH_y[] = "!@@";
char ASH_z[] = "**@";

char t[] = "ash code";
const int oblen = 100;
char ob [oblen];



void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  Serial.println(ASH2ASCII("!**")); //These are the ASH characters I want to convert to using the ASH2ASCII function
  Serial.println(ASH2ASCII("!"));
  Serial.println(ASH2ASCII("!*@"));
  Serial.println(ASH2ASCII("!*@"));
  Serial.println(ASH2ASCII("@*"));


  ASCII2ASH (t, ob, oblen);
  Serial.println(ob);


}


void ASCII2ASH (char * ip, char * op, int oplen) {

  op[0] = '\0';
  int bp = 0;
  int n;
  char m[9];
  int l = strlen(ip);
  for (int i = 0; i < l; i++) {

    strcpy(m, ASCII2ASH(ip[i]));
    n = strlen(m);
    if ((bp + n + l) < oplen) {
      strcat(op , m);                                                                                                                                                                                                                                
      bp = bp + n;
    }
    if (ip[i] != ' ' && ip[i + l] != ' ') {
      op[bp] = '/';
      bp++;
    }
    bp++;
    op[bp] = '\0';
  }
}

char ASH2ASCII(char * m) { //Using the char variables impmented globally, ASH2ASCII searches through specific variables until it finds a match for the conversion, at which point it will capture and reuturn the ASCII string

  if (strcmp(ASH_a, m) == 0) { //if string captured return a
    return 'a';
  }
  else if (strcmp(ASH_b, m) == 0) { //else if b string is captured return 
    return 'b';
  }
  else if (strcmp(ASH_c, m) == 0) {
    return 'c';
  }
  else if (strcmp(ASH_d, m) == 0) {
    return 'd';

  }

  else if (strcmp(ASH_e, m) == 0) {
    return 'e';

  }
  else if (strcmp(ASH_f, m) == 0) {
    return 'f';

  }

  else if (strcmp(ASH_g, m) == 0) {
    return 'g';

  }
  else if (strcmp(ASH_h, m) == 0) {
    return 'h';

  }
  else if (strcmp(ASH_i, m) == 0) {
    return 'i';

  }
  else if (strcmp(ASH_j, m) == 0) {
    return 'j';

  }
  else if (strcmp(ASH_k, m) == 0) {
    return 'k';

  }
  else if (strcmp(ASH_l, m) == 0) {
    return 'l';

  }
  else if (strcmp(ASH_m, m) == 0) {
    return 'm';

  }
  else if (strcmp(ASH_n, m) == 0) {
    return 'n';

  }
  else if (strcmp(ASH_o, m) == 0) {
    return 'o';

  }
  else if (strcmp(ASH_p, m) == 0) {
    return 'p';

  }
  else if (strcmp(ASH_q, m) == 0) {
    return 'q';

  }
  else if (strcmp(ASH_r, m) == 0) {
    return 'r';

  }
  else if (strcmp(ASH_s, m) == 0) {
    return 's';

  }
  else if (strcmp(ASH_t, m) == 0) {
    return 't';

  }
  else if (strcmp(ASH_u, m) == 0) {
    return 'u';

  }
  else if (strcmp(ASH_v, m) == 0) {
    return 'v';

  }
  else if (strcmp(ASH_w, m) == 0) {
    return 'w';

  }
  else if (strcmp(ASH_x, m) == 0) {
    return 'x';

  }
  else if (strcmp(ASH_y, m) == 0) {
    return 'y';

  }
  else if (strcmp(ASH_z, m) == 0) {
    return 'z';

  }

}

void ASCII2ASH (char * buf) {

  Serial.println(ASCII2ASH(*t));

}


char * ASCII2ASH (char c) { //This is the opposire of ASH2ASCII, it uses the globally defined variables to search through ASCII characters, and returns the ASH version of that character

  switch (c) {

  case 'a':
    return ASH_a;//returns ASH version of a if matched

  case 'b':
    return ASH_b;

  case 'c':
    return ASH_c;

  case 'd':
    return ASH_d;

  case 'e':
    return ASH_e;

  case 'f':
    return ASH_f;

  case 'g':
    return ASH_g;

  case 'h':
    return ASH_h;

  case 'i':
    return ASH_i;

  case 'j':
    return ASH_j;

  case 'k':
    return ASH_k;

  case 'l':
    return ASH_l;

  case 'm':
    return ASH_m;

  case 'n':
    return ASH_n;

  case 'o':
    return ASH_o;

  case 'p':
    return ASH_p;

  case 'q':
    return ASH_q;

  case 'r':
    return ASH_r;

  case 's':
    return ASH_s;

  case 't':
    return ASH_t;

  case 'u':
    return ASH_u;

  case 'v':
    return ASH_v;

  case 'w':
    return ASH_w;

  case 'x':
    return ASH_x;

  case 'y':
    return ASH_y;

  case 'z':
    return ASH_z;

  case ' ':
    return " ";

  default:
    Serial.println("switching went wrong!");
    break;

  }
}



void loop() {


}

technically you cannot detect as ASH is a subset from ASCII. The only thing you can do is a statistical analysis saying that the chance some stream is ASH is approaching 100%. However you can be sure it is ASCII if some non ASH char is entered.

so read the first 30 chars in a buffer, if they all appear !@ or * you can "safely" ASSUME it is ASH

bool isASH(char* buf)
{
  for (int i=0; i<30; i++)
  {
    if (buf[i] != '*' && buf[i] != '!' && buf[i] !='@') return false;
  }
  return true;
}

robtillaart:
technically you cannot detect as ASH is a subset from ASCII. The only thing you can do is a statistical analysis saying that the chance some stream is ASH is approaching 100%. However you can be sure it is ASCII if some non ASH char is entered.

so read the first 30 chars in a buffer, if they all appear !@ or * you can "safely" ASSUME it is ASH

bool isASH(char* buf)

{
  for (int i=0; i<30; i++)
  {
    if (buf[i] != '*' && buf[i] != '!' && buf[i] !='@') return false;
  }
  return true;
}

Thanks, I have never used the bool type so didn't know it could be used to determine true or false!
However, how would I put a bool statement inside a function, as I'll need to call it so the statement can be applied to the users input? Thanks!

the users input is placed in a buffer and that buffer is handed over to the function.

If you want to do it runtime you need something like

#define ASH 0
#define ASCII 1

...

if (Serial.available())
{
char c = Serial.read();
if (c != '*' && c != '!' && c !='@')
{
decodeMode = ASCII;
}
...
}