Where should I put my bool if statement to get it to work?

Hi, I’m creating a function that converts ASCII to ASH or vice versa. After doing some research and getting some answers from other programming forums such as stack overflow I have pieced together some code:

This code is to take the user input and store it in a char, however, I am struggling to link it with my 2 other functions/statement below.

void usinput(char * ib ){
  char inChar;
  for(int i = 0; inChar != ib[i]; i++){
     while(!Serial.available()) { 
    }

    inChar = Serial.read();
    ib[i] = inChar;
  }
}

This is my bool statement that is going to search for whether the user has entered ASCII or ASH, it uses char variables which I have defined at the top of my program, but now I’m just trying to provide you with the bits I’m stuck on to try and get some help :).

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

}

This if statement is meant to act on whether the bool statement is true or false, by calling a function to either convert ASH to ASCII or ASCII to ASH.

if (isASH(&buf)) {
  ASHtoASCII(char * m);
}else{
  ASCII2ASH (char * ip, char * op, int oplen);
}

However, I’m not sure how I would peice this together, I don’t know where I’d put the if statement, as when I put it in the function “void usinput” at the top, it comes up with errors.
I want the user to be able to enter ASH or ASCII into the serial port, then for the bool statement to run, and then one of the two functions in the if statement needs to be executed to perform the relevant translation. Can anyone offer any help, I think I’m close to a solution now I just need someone with abit more experience to tell me where to put the if statement and such :)!

What is "ASH" ?

KenF:
What is "ASH" ?

It's text made up of just '!' '*' and '@' I wouldn't want to perform this translation personally but it's for an assignment :slight_smile:

lewrossi:
It's text made up of just '!' '*' and '@' I wouldn't want to perform this translation personally but it's for an assignment :slight_smile:

Do you have any examples?

KenF:
Do you have any examples?

I just included an example screenshot in the post :slight_smile:

Relates to this thread where I supplied some code already

robtillaart:
Relates to this thread where I supplied some code already

Thanks for the help that's my post from yesterday :slight_smile: I'm just not sure where the if statement would be placed, would I put it in the usinput function?

Looking at your table. What's the difference between AE (!) and D (!)

KenF:
Looking at your table. What's the difference between AE (!) and D (!)

Good question, I think if the first character in a string is an ! you put a space, but I know what you're saying its a pretty weird language :confused: