C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-10-2009, 12:41 PM   #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
seidel is offline   Reply With Quote
Old 08-10-2009, 12:52 PM   #2
Super Moderator
 
Join Date: Sep 2001
Posts: 4,680
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
}
sean is offline   Reply With Quote
Old 08-11-2009, 10:19 AM   #3
Registered User
 
Join Date: Jan 2007
Location: Euless, TX
Posts: 135
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;
kcpilot is offline   Reply With Quote
Reply

Tags
code

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 10:14 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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