There is no way in C/C++ that I know of. I use the first element of the array to hold the number of elements (like in turbo pascal with strings : string[0] holds length). If you are using char, then it will limit you to 255 elements.
Code:
#include <string.h>
#include <stdlib.h>
#include <iostream.h>
void doSomething(char *cptr)
{
int numElements = cptr[0];
for (int i = 1; i <= numElements; i++)
{
cout << "Element " << i << " = " << cptr[i] << endl;
}
}
int main()
{
char teststring[] = "this is some text";
int len = strlen(teststring);
char * temp = new char[len + 1];
temp[0] = len;
strcpy(&temp[1], teststring);
doSomething(temp);
delete[] temp;
return 0;
}
This works fine in Borland C++ 5.02. You can also try using list, vector, etc.