How do you initialize a char array of pointers to NULL
<p>I am trying to initialize a array of <code>char*</code> to <code>NULL</code> in my constructor for my class called <code>Student</code>. I pass in the array to the constructor and this is the code I use to initialize the array to <code>NULL</code> in a loop</p>

<pre><code>Student:: Student(int iID, char *mName, char *wName, char *hName, char *className[8])
{
    setStudentID(iID);

    setName( mName,  wName);
    setHouse( hName);

    for(int i=0;i&lt;7;i++)
    {
        m_sClasses[i]=NULL;
        //setClass(i,className);
    }
}
</code></pre>

<p>In my <code>main</code>, I define the array as <code>char *getclass1[8]={};</code> since i have to initialize it to something as it will cause an error if I don't.</p>

<p>I then call my constructor and pass in the values to initialize the class instance</p>

<pre><code>Student s1(1,firstname,wizardfamilyname,housename,getclass1);
</code></pre>

<p>and my student.h has the constructor defined like so</p>

<pre><code>Student(int iID, char *mName, char *wName, char *hName, char *className[8]);
</code></pre>

<p>and the array that i am initializing in my constructor is declared like so in my .h file</p>

<pre><code>char *m_sClasses[8];
</code></pre>

<p>yet when i try to run the program it gives me the following runtime error</p>

<pre><code>CXX0030: Error: expression cannot be evaluated - m_sClasses[i] 0xcccccccc &lt;Bad Ptr&gt; char * 
</code></pre>

<p>apologies    ....here is my .h file that defines my interface</p>

<pre><code>enter codclass Student
</code></pre>

<p>{
      private:
           int m_iStudentID;
           char m_sMagicalName[65];
           char m_sWizardFamilyName[65];
           char m_sHouse[65];
           char *m_sClasses[8];
           int m_iGrades[8];</p>

<pre><code>   public:
          //constructor
          Student();
          Student(int iID, char *mName, char *wName, char *hName, char *className[8]);
          //destructor
          ~Student();
             int getStudentID() ;
             void setStudentID(int iID);
             void getName(char *mName, char *wName);
             void setName(char *mName, char *wName);
             void getHouse(char *hName);
             void setHouse(char *hName);

             void getClass(int idx, char *className);
             void setClass(int idx, char *className);
             void getGrade(int idx, int &amp;iGrade, char &amp;cGrade);
             void setGrade(int idx, int grade);
             void printStudentInfo();
</code></pre>

<p>};</p>

<p>this is my .cpp file where i implement my class interface(i only include the constructor and the setclass as every other fucntion is working and i will not waste space</p>

<pre><code>       #include "student.h"
      #include &lt;iostream&gt;
      #include &lt;string.h&gt;


     //call the student constructor

     Student:: Student(int iID, char *mName, char *wName, char *hName, char *className[8])
   {
       setStudentID(iID);

       setName( mName,  wName);
       setHouse( hName);

       for(int i=0;i&lt;7;++i)
       {
                       m_sClasses[i]=NULL;
                       //setClass(i,className);
       }

    }
</code></pre>

<p>once you call the constructor to initliaze the class and set the array of pointers to point to null you now call the set class function in main to set the class</p>

<pre><code>  void Student:: setClass(int idx, char *className)
  {
               if(m_sClasses[idx]!=NULL);
               {
                  delete m_sClasses[idx];
                  m_sClasses[idx]=new char[strlen(className)+1];
                  strcpy(m_sClasses[idx],className);
               }
   }
</code></pre>

<p>last but not least in my main (main entyr point) where i intilialize student and then </p>

<pre><code>char *getclass1[8]={};
char getclass2[65]="";
char gethouse1[65]="";
      //call constructor
Student s1(1,firstname,wizardfamilyname,housename,getclass1);


  //call the set function and set the class

  s1.setClass(1,class1);
</code></pre>

<p>i get a runtime error which i explained in the original post
sorry i forgot to include the class1 array which actually contains the char array of the class the student is taking</p>

<pre><code>  char class1[65]="Computer programming";
</code></pre>
