How can I create an array of strings in C/C++ ? I can use an array
of pointers for a finite number of strings like MAXSIZE as char
*array[MAXSIZE-1]; Can I use a pointer to pointer char **array; for
infinite number of strings? If that is the case how will I
initialise the char ** ?

Follows the code I am trying....

class DynamicStringArray
{

      private:
          char **ptrptr;  //I am usinng char ** instead of char *[]
          int position;

      public:
      DynamicStringArray()
      {           
            ptrptr=0;position=0;
      }
      void addString(char *ptr)
      {
                ptrptr[position]=new char(strlen(ptr) +1); //crash here
         strcpy(ptrptr[position],ptr);
         position ++;
      }
      void displayString(int data)
      {
            cout<<"String at "<<data<<"is:"<<ptrptr[data]<<endl;
      }

};

This program is crashing at addString() function at first line.

Please help me in this regards,

Pratheesh.








To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.


Yahoo! Groups Sponsor
ADVERTISEMENT
click here


Yahoo! Groups Links

Reply via email to