I just need to know how to count the entries of an array like this one:

string array[] = {"entry", "entry", "entry", ... , "entry"};

Thanks!

Thanks! now is there a way that I can make a shortcut for that? say...if I wanted to make a function arraycount(array) how would I do that so I don't have to type tha long stuff?
I'm not talking about doing

int arraycount(string array)
{
  int z = (sizeof array / sizeof array[ 0 ]);
  return(z);
}

or some similar code but like to hardwire a new command?
thx

Thanks! now is there a way that I can make a shortcut for that? say...if I wanted to make a function ...
I'm not talking about doing

int arraycount(string array)
{
  int z = (sizeof array / sizeof array[ 0 ]);
  return(z);
}

What's wrong with your example?

What's wrong with your example?

Try it and see.

Thanks! now is there a way that I can make a shortcut for that? say...if I wanted to make a function arraycount(array) how would I do that so I don't have to type tha long stuff?

Consider a macro.

#define arraycount(x) (sizeof(x)/sizeof(*(x)))

An array of STL strings seems a little strange. Have you considered using STL vectors instead of arrays? They have a built in size() member, no calculation on your part is needed.

This article has been dead for over six months. Start a new discussion instead.