NUR,
Are you trying to avoid dynamic memory?
The reason I ask is because Banfa is giving you the best suggestions.
Not only will line 1,
char RetVal[500][];
not compile, but line 3,
RetVal[0][]= "Start Value";
will also fail to compile, when used as is.
So, as Banfa observes, if you are using C++, the vector of strings method is really the best (and safest) way to go about managing your array.
However, as you are apparently using C
This piece of code above is incorrect. How do I code such a thing such that it gets correctly compiled on a c-compiler?
so you will have to do something similar to the following code:
- #define array_size 500
-
typedef char ManyStrings[array_size][500];
-
-
ManyStrings *myFunc()
-
{
-
static ManyStrings RetVal;
-
-
strcpy(RetVal[0], "Start Value");
-
for(IndexX = 1; IndexX < array_size-1; IndexX++)
-
{
-
strcpy(RetVal[IndexX], "middle values");
-
}
-
-
strcpy(RetVal[array_size-1], "End Value");
-
-
return &RetVal;
-
}
However, my example is simply an extension of the code you provided. It really wastes memory, and not amenable to arrays of truly significant size. Specifically, the array, as declared, takes 250k of memory.
How you ultimately resolve your problem depends on the problem's requirements.