0

so im trying to create an array with const char everytime the function is called i want to add to my array like a strtok

so if i to wanted set

struct R2R
{
private:
    int Index;

    const char* DvarA[10000];
    const char* DValueA[100000];

public:
    void AddInfDvar( int DvarCount ,const char* Dvar, const char* Value)
    {
        setClientDvar(Dvar, Value);
        DvarA[DvarCount] = Dvar;
        DValueA[DvarCount] = Value;

    }
}R2R;

so if i called it like this

DvarA[1] = "Test";

GetDvar(int Num)
{
 return DvarA[Num];
}

would it return Test?

i just want to make sure im doing it right

T.Shepherd
  • 13
  • 2
  • 6

1 Answers1

0

The code you've set up creates an array of 10,000 const char*s, each of which can be thought of as a pointer to an immutable C-style string. Therefore, if you write

DvarA[1] = "Test";

you're storing a pointer to the string literal "Test" into slot 1 in the array. If you then read it back later, you will indeed get back "Test."

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
  • i thought as such thank for you for the quick reply. another thing could would it work if i used as a for script im not too familier with C++ only self taught for(int i = 0; i < DvarsA.size; i++) – T.Shepherd Mar 02 '16 at 22:56