DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: char **

Hybrid View

  1. #1
    Joe Guest

    char **


    I'm trying to make an array of character strings and i'm not sure how to do
    it. I'm thinking I define a char** but then how do I allocate space or access
    it once it has been created. Thanks.

  2. #2
    Danny Kalev Guest

    Re: char **

    you really don't want to get into this trouble. Why not use an array of
    real string objects, e.g.,

    #include <string>

    std::string sarr[10];

    Danny
    Joe wrote:
    >
    > I'm trying to make an array of character strings and i'm not sure how to do
    > it. I'm thinking I define a char** but then how do I allocate space or access
    > it once it has been created. Thanks.


  3. #3
    arbitrary Guest

    Re: char **


    "Joe" <protoplasm@geocities.com> wrote:
    >
    >I'm trying to make an array of character strings and i'm not sure how to

    do
    >it. I'm thinking I define a char** but then how do I allocate space or

    access
    >it once it has been created. Thanks.


    You probably want to do what the other guy said but i'll oblige. First
    you need to allocate an array of char*'s or the array that will hold the
    strings. Then you allocate space for each string. I don't know what your
    input is going to be like but something like this.

    char** notsogoodidea (int number, int strsize)
    {
    char **p = new char*[number];
    if (!p)
    return null;
    for (int i = 0; i < number; i++)
    p[i] = new char[strsize];
    return p;
    }

    no guarantees that this will work. I just spent a term coding in an
    obscure lisp based language and i havent't ouched C++ in a while.
    Good luck. Just remember to deallocate everything.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center