Thread: C and pointers help
-
March 8th, 2009, 03:26 PM #1
C and pointers help
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
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: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]; }
but instead useCode:entry[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.Code:entry_node[j]->num_tasks;
http://www.tekshome.com
YAY!!!!!!!!!
-
March 15th, 2009, 10:30 AM #2
I forget the exact syntax, but can you try to "catch" the exception if malloc fails?
That one program way back when messed with my head too...an array of pointers to pointers...ugh!
ROFL
Good Luck...if you need more help I will, but this stuff gives me headaches!!
I thought we coded something like: int **data_ptr;Last edited by Rootstonian; March 15th, 2009 at 10:32 AM.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
c++ pointers
By lost-and-found in forum Webmastering and ProgrammingReplies: 5Last Post: August 23rd, 2004, 08:21 PM -
Pointers?
By Brainchild in forum IMO CommunityReplies: 8Last Post: July 23rd, 2004, 06:58 PM -
C++ - Pointers and Practicality
By Iturea in forum Webmastering and ProgrammingReplies: 3Last Post: January 22nd, 2004, 11:39 PM -
Pointers as parameters...HELP!
By squeech in forum Webmastering and ProgrammingReplies: 1Last Post: September 16th, 2003, 10:45 PM -
C++ pointers
By Damien019 in forum Webmastering and ProgrammingReplies: 5Last Post: May 1st, 2003, 11:00 PM



LinkBack URL
About LinkBacks




Reply With Quote

that was easy, if only deleting the partition was that simple.
Is It Just Me? v233893843