struct pointers

This is a discussion on struct pointers within the C Programming forums, part of the General Programming Boards category; Hi! I was wondering how it would be done to point to struct, like this you have two dif structs ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    5

    struct pointers

    Hi!

    I was wondering how it would be done to point to struct, like this

    you have two dif structs

    Code:
    typedef struct {
         float face1,face2,face3;
        char name[200];
         int num_objs;
    
    } object_list;
    
    typedef struct {
         scene_name
           
    }scenes;
    
    
    object_list obj[50];
    scenes scene[50];
    where scene would be 1 element, and pointing to several objects with in the

    (this is pseudo and what i want todo)

    scene[0].obj[0].numobj;

    result with how many objects there are in scene 0, right now i add the start object and the end object into the scene struct so, when drawing the 3d object, i do
    this more or less.
    Code:
    for (counter=startobj;counter<endobj;counter++)
    anyone could elaborate how i could do this?

    Any help are appricated!

    - seidel

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    If you're asking how to iterate through a series of structs, you have at least two options. Here they are in somewhat-pseudo-code:


    As an array
    Code:
    my_type objects[50];
    int length = 50;
    ...
    for(i = 0; i < length; i++) {
         // Do some stuff with objects[i]
    }
    As a linked list (i.e. the struct contains a pointer that is used to point to the next instance in the series)

    Code:
    struct my_type {
        int data[50];
        struct my_type * next;
    } current;
    ...
    for(current = start; current.next != NULL; current = current.net) {
        // Do some stuff with current
    }

  3. #3
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    For one thing, struct scene DOES NOT contain an 'obj', so your 'scene[0].obj[0].numobj;' is completely bogus.

    To do what you want to do, you would have to include the structure 'object_list' INSIDE your scene struct.

    Code:
    typedef struct {
         float face1,face2,face3;
        char name[200];
         int num_objs;
    
    } object_list;
    
    typedef struct {
         scene_name
         struct object_list[50];
           
    }scenes;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Concatenating in linked list
    By drater in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 11:10 PM
  2. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  3. Function validation.
    By Fhl in forum C Programming
    Replies: 10
    Last Post: 02-22-2006, 07:18 AM
  4. Array of struct pointers - Losing my mind
    By drucillica in forum C Programming
    Replies: 5
    Last Post: 11-12-2005, 10:50 PM
  5. Pointers on pointers to pointers please...
    By Morgan in forum C Programming
    Replies: 2
    Last Post: 05-16-2003, 11:24 AM

Tags for this Thread


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