Thread: structure question

  1. #1
    Unregistered
    Guest

    structure question

    typedef struct {
    char name[][MAX1];
    char state[][MAX1];
    char id[]MAX1];
    } Station;

    for some reason i can't get this to compile.
    but when i make each of the arrays to one dimension it compiles.
    am i able to have 2d arrys in structures??

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    typedef struct {
    char name[][MAX1];
    char state[][MAX1];
    char id[]MAX1];
    } Station;

    These are not considered 2D arrays. They are incorrect. You can use 2D arrays, you just have to specify the size:

    Code:
    struct mystruct {
        char array[3][45];
    };
    There is no point in having your 2D array as you have described it. Remember this:

    You can only use empty [] for an array argument when you are providing the data for it at that time:

    Code:
    struct somestruct mytable[] = {
        { "hello", 20, 4.33 },
        { "whee", 453, 1.302 },
        { "goodbye", 3, 0.12 },
        { "", 0, 0.0 }
     };
    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 12-14-2007, 03:34 PM
  2. Simple C# structure question
    By sketch in forum C# Programming
    Replies: 4
    Last Post: 09-14-2007, 04:29 PM
  3. question about data structure
    By renaissance in forum C++ Programming
    Replies: 3
    Last Post: 02-17-2005, 01:47 PM
  4. data structure question
    By miami_victor in forum C++ Programming
    Replies: 13
    Last Post: 12-31-2004, 12:56 AM
  5. Array and Structure Question
    By loopshot in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2004, 05:10 PM