Essentially an "array of pointers" problem

This is a discussion on Essentially an "array of pointers" problem within the C Programming forums, part of the General Programming Boards category; This is definitely my problem area of C. Can anyone point me to a decent tutorial/faq on this? I can't ...

  1. #1
    Not bad at Crack Attack!
    Join Date
    Aug 2003
    Posts
    45

    Essentially an "array of pointers" problem

    This is definitely my problem area of C. Can anyone point me to a decent tutorial/faq on this? I can't seem to find one on this site but I may well be wrong!

    My problem is essentially this:
    I need to make an array of arrays (m of them) of different sizes - altho helpfully each array is one int less than the previous.

    I get m from the user then use:
    Code:
      int *tray[m];
      for(i=0; i<N; i++)
        *tray[i]=(int*)calloc((N-i),sizeof(int));
    to make each array of a given size. I know this is a big mess ("parse error before int") but I can't find any help on getting around it.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    >> *tray[i]=(int*)calloc((N-i),sizeof(int));

    No need to dereference the array element there, just do:

    tray[i]=(int*)calloc((N-i),sizeof(int));
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  3. #3
    Not bad at Crack Attack!
    Join Date
    Aug 2003
    Posts
    45
    Thanks. I have implemented this but the compiler seems to be having more fun with the declaration of trays generally.

  4. #4
    Not bad at Crack Attack!
    Join Date
    Aug 2003
    Posts
    45

    And the moral of the tale is...

    ... always use google!

    http://www.eskimo.com/~scs/cclass/int/sx9b.html (in case anyone else is interested!)

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21