Question:

How do I get an array of char* in C++?

by  |  earlier

0 LIKES UnLike

I am trying to store a whole bunch of char* strings in an array, but I forget how to dynamically initialize an array of char*, can anyone help me?

Am I supposed to do

char** headerArray = new char*[headerCount];

for(int i=0;i<headerCount;i++)

headerArray[i] = new char*[MAX_LENGTH];

????

 Tags:

   Report

2 ANSWERS


  1. Yes, you are correct (you must use a loop)


  2. remember the main (int argc, char *argv[]), that argv is the array of char *;

    Wish the following code will be helpful,

    ---

    int max = 100;

    char s2a [max][max];

    for (int i=0; i &lt; max; i ++){

        strcpy (s2a[i], &quot;abc&quot;);

    }

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.