Thread: Just a quickie

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    23

    Just a quickie

    hey,

    Just having trouble with creating a 2d array in the heap memory.

    my code goes something like this:

    twoDarray = new char[iSize][iSize];

    where iSize is passed into the method.

    cheers,
    ActionMan
    ActionMan

    "THE DAY IS MYNE!!!!
    I'll take famouse titties for $400"
    -Sean Connery, Saturday Night Live

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    23
    sorry forgot to say that twoDArray is declared as follows..

    char ** twoDarray;
    ActionMan

    "THE DAY IS MYNE!!!!
    I'll take famouse titties for $400"
    -Sean Connery, Saturday Night Live

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    You cannot do it like that. A char** is a pointer to a pointer!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I believe this is what you're looking for...


    Code:
    
    
    
    char **NewMatrix(int rows, int columns)
    {
      char **matrix = new char*[rows];
    
      while(rows)
      {
       matrix[--rows] = new char[columns];
    
       memset(matrix[rows], 0, columns);
      }
     return matrix;
    }
    
    
    
    
    
    //...You MUST call this to free up the memory...
    
    void KillMatrix(char** matrix, int rows)
    {
      while(rows)
      delete [] matrix[--rows];
    }
    
    int main(int argc, char *argv[])
    {
    int i, rows = 20, cols = 50;
    
    char **strings = NewMatrix(rows, cols);
    
    for(i = 0; i < rows; i++)
    sprintf(strings[i], "\nString #%i", i+1);
    
    for(i = 0; i < rows; i++)
     {
      printf(strings[i]);
      getch();
     }
    
    printf("\n\n\nDeallocating Array!");
    
    getch();
    
    KillMatrix(strings, rows);
    
      return 0;
    }
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    23

    thanks

    hey,

    thanks.. that the way I origionally had it. I was hoping new was a little more advanced.

    thanks for the help!!

    cheers,
    ActionMan

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. vector and pointer - quickie
    By Zishaan in forum C++ Programming
    Replies: 2
    Last Post: 03-27-2007, 01:46 PM
  2. Quickie Linked List Deallocation question.
    By Kurisu in forum C# Programming
    Replies: 4
    Last Post: 06-09-2006, 07:23 AM
  3. Quickie: typedef
    By Trauts in forum C++ Programming
    Replies: 1
    Last Post: 05-19-2003, 06:45 PM
  4. quickie pointer question
    By 1337speaker in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2003, 05:55 PM
  5. Quickie Q :o) (yea!!)
    By JohnMayer in forum C Programming
    Replies: 2
    Last Post: 07-23-2002, 12:09 PM