referring to array index?

Howdy.

I have an array of pointers to char arrays or c-strings(that's my goal anyway) and I'm trying to pass the index of a certain string as an int parameter. ie:

const char *t[3] =
{
"string 1",
"string 2",
"string 3"
};

I want to pass the index of "string 2" as a parameter in a function but referring to the string in the case that I don't know what index "string 2" is located at.

EDIT: so function DoSomething( int number);

DoSomething("string 2");

how would I do this, would I typecast it somehow or is there a built in operator to refer to a string's index number in the array?
Last edited on
you need to search for "string 2" in the array. Something like
1
2
3
4
5
6
7
8
9
10
11
12
int CalculateIndex(char* s, char*t[3])
{
   int index=-1;
   for(int i=0;i<3;i++)
  {
      if(strcmp(s,t[i])==0)
     {
         index=i;
     }
   }
   return i;
}
Topic archived. No new replies allowed.