Create a table according input

Hello,I am beginer in arduino. in my program I get a word data from serial port . now I want to create a table to get me a char according this word for example if the word is 10 , table get me "char2" and etc

Char=[ “char1”,”char2”, ”char3”,”char4”,”char5, … ,”char200]
Word 10=char2
Word 110=char1
Word 122=char3
Word 145=char4
.
.
.
Word 350=char200

Can anyone help me?

Can anyone help me?

No. I do not understand what you are trying to do.

Post the code you actually have. That psuedo code is nonsense.

Post an example of the serial data you are sending, and an example of what you want to create from it.

I don't write code for this section of my program
So I have many word and character and number of word and char are equal

Char=[ "char1","char2", "char3","char4","char5, … ,"char200]
word=[ 10,110,122,145,160,...,350]

now i Want to communicate each word to its char, and I don't know how to do ,use table or other way ,I don't know

That all doesn't make much sense. Aka, it's a classic XY-problem

I think you are saying you want to parse a serial stream. Perhaps explain better the nature of that stream
rather than getting bogged down in any detail - say what you want to achieve, with concrete examples,
not how you imagine it should be done.

bolton1391:
I don't write code for this section of my program
So I have many word and character and number of word and char are equal

Char=[ "char1","char2", "char3","char4","char5, … ,"char200]
word=[ 10,110,122,145,160,...,350]

now i Want to communicate each word to its char, and I don't know how to do ,use table or other way ,I don't know

I con't understand the actual problem.
Can you describe it a bit more detailed?
If so, please use simple words as English is not my mother language!

This what I have understood so far (might be wrong):

You have some kind of "sentence" and the sentence is stored in a char array like maybe:

char sentence="lorem ipsum dolor sit amet consectetur adipiscing elit";

And now you want to parse the sentence for all the words in it, and create an array of words, which are part of the sentence.
Is it something like that you want?

i would liketo Write a program same this example. But I don't like to use "If" and I would like to use better method ???

example:

char* myStrings={"string 1", "string 2", " string 3","string 4", ...,"string n"};
word ab;

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

void loop(){
ab=Serial.read(); // data is a word

if (ab==10)then Serial.println(string 1);
if (ab==110)then Serial.println(string 2);
if (ab==112)then Serial.println(string 3);

.
.
.

if (ab==350)then Serial.println(string n);

}

Is there any logic in the mapping?

If not, you can make use of a struct that links a text to a number. To give you the idea, below code.

struct ITEM
{
  char *txt;
  int ab;
};

ITEM lookup[]  =
{
  {"hello", 3},
  {"world", 9},
};

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

void loop()
{
  if (Serial.available() > 0)
  {
    char ch = Serial.read();
    if (ch >= 0 && ch <= 9)
    {
      ch -= '\0';

      for (int cnt = 0; cnt < sizeof(lookup) / sizeof(lookup[0]); cnt++)
      {
        if(lookup[cnt].ab == ch)
        {
          Serial.println(lookup[cnt].txt);
        }
      }
    }
  }
}

First the struct is defined. Next an array of those structs is declared and populated.

The loop part loops though all array elements and compares the serial input with the ab variable and prints if they match.

The code only demonstrates for numbers 0…9; you need a different approach for the serial read to cater for multi-digit numbers.

Compiles but not tested.