March 8th, 2009, 04:26 PM
|
#1 (permalink)
|
| Ultimate Member
Join Date: Oct 2001 Location: Illinois
Posts: 2,977
|
Wow, it's been a while since I actually asked for help here, but here it goes.
I'm writing a C program that is using some pointers, pointers to pointers, etc.
Here's a small example of what my code needs to do Code: typedef struct{
int num_tasks;
int* task_list; //a variable sized array of tasks
} entry;
typedef struct{
entry *ref_to_entry;
} entry_node_t;
int main(){
/* some code here that is irrelevant */
entry *user_entry;
user_entry = (entry*) malloc (num_entries*sizeof(entry)); //assume num_entries is obtained from user input during runtime
entry_node_t* entry_node;
entry_node = (entry_node_t*) malloc(num_entries * sizeof(entry_node_t));
for(int i=0;i<num_entries;i++)
entry_node = &user_entry[i];
}
Basically, in the above code I would like entry_node to be an array of pointers to each user_entry. I know I could just store the index to entry inside entry_node, but I would like it to be a pointer so that I don't have to write: Code: entry[entry_node[j]].num_tasks;
but instead use Code: entry_node[j]->num_tasks;
Am I doing something wrong? I try to compile and it compiles, but it doesn't seem to allocate space for entry_node. |
| |