Thread: 2d array of structures

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    41

    2d array of structures

    Hi there. I have a 2d array of structures and i am having trouble getting at them. I'm still relatviley new and pointers are *not* my forté.

    I've sent the whole code below, cause i really dont know what's going on.

    Its supposed to be a mars rover simulation, now I'm really nowhere near completion, but I'm working on the "move" command. I need to have some sort of pointer pointing to a position in trhe array, and then move it either up down left right etc within the array. i was thinking of maybe using th gridx and gridy ints within the structure. How do i set up a pointer to the 2d array of structures? I currently am making the map within a function (and as such, probably have to pass a pointer to it as an argument)

    Desperate cry, i'm really not having fun with this. in the make map function, do i have to return the pointer? ok let me rephrase that. How do i return a pointer from a function? or do i just set the pointer up within the function and then be able to access it outside the program?

    Maybe a look at my code below might help.?

    *desperate face*

    I'm hoping getting one function right will get me set up for the rest

    Cheers for _any_ input you may have
    ta,

    Mitch
    ~~~~~~~~~~
    Mitchell Kent
    07782383326
    [email protected]
    ~~~~~~~~~~

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Try:
    Code:
    location ** make_map(int mapsizex, int mapsizey)
    {
       location **map;
       ...
       return map;
    }
    
    int main(void)
    {
       location **map;
    
       map = make_map(8, 8);
    
       return 0;
    }

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    41
    worked a treat - perfect in fact!

    ta very much

    Mitch
    ~~~~~~~~~~
    Mitchell Kent
    07782383326
    [email protected]
    ~~~~~~~~~~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How To Declare and Dynamically Size a Global 2D Array?
    By groberts1980 in forum C Programming
    Replies: 26
    Last Post: 11-15-2006, 09:07 AM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  3. Array of Structures: Sorting
    By Drainy in forum C Programming
    Replies: 3
    Last Post: 04-13-2005, 09:55 AM
  4. 2d array problem
    By LiLgirL in forum Windows Programming
    Replies: 1
    Last Post: 03-15-2004, 02:23 PM
  5. how to pass 2D array into function..?
    By IngramGc in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2001, 08:41 AM