structure question

This is a discussion on structure question within the C Programming forums, part of the General Programming Boards category; typedef struct { char name[][MAX1]; char state[][MAX1]; char id[]MAX1]; } Station; for some reason i can't get this to compile. ...

  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, 02: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, 12:47 PM
  4. data structure question
    By miami_victor in forum C++ Programming
    Replies: 13
    Last Post: 12-30-2004, 11:56 PM
  5. Array and Structure Question
    By loopshot in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2004, 05:10 PM

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