home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

C and pointers help

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2508
Discussions: 201,011, Posts: 2,380,100, Members: 246,377
Old March 8th, 2009, 04:26 PM   Digg it!   #1 (permalink)
Ultimate Member
 
lost-and-found's Avatar
 
Join Date: Oct 2001
Location: Illinois
Posts: 2,977
Send a message via AIM to lost-and-found
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
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.
__________________
lost-and-found is offline   Reply With Quote
Old March 15th, 2009, 11:30 AM     #2 (permalink)
Caveat Emptor
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 3,242
Send a message via AIM to Rootstonian
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 11:32 AM.
Rootstonian is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ pointers lost-and-found Webmastering and Programming 5 August 23rd, 2004 09:21 PM
Pointers? Brainchild IMO Community 8 July 23rd, 2004 07:58 PM
C++ - Pointers and Practicality Iturea Webmastering and Programming 3 January 22nd, 2004 11:39 PM
Pointers as parameters...HELP! squeech Webmastering and Programming 1 September 16th, 2003 11:45 PM
C++ pointers Damien019 Webmastering and Programming 5 May 2nd, 2003 12:00 AM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (3137)
‘Rogue’ or ‘Rouge’? (10)
Charges against non-tippers dropped.. (22)
Foxconn Blackops x48 MoBo (6)
Nvidia GTX 260 problem (14)
Delete an OS (18)
Laptop with wireless problem. (14)
Wireless Televisions. (12)
CPU fan stops spinning randomly (11)
Regular Build (11)
Point and Shoot Camera Suggestions. (9)
windows vista security holes (19)
[F@H SPAM 11/16/09] ! 1/2 months to.. (43)
windows 7 problem (7)
Recent Discussions
Please Help. (1)
winrar decompresses, but video gone (0)
Advice for stopping IRQ BSOD is win7 (0)
Foxconn Blackops x48 MoBo (6)
downloading error for Creative prodik.. (0)
Outputing 1080p from my PC to my 720p.. (1)
Need idiot-proof help for building a .. (3)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (43)
Computer shutting down on its own (7)
Hp Artist Edition + Matching Bag (1)
cant access the internet (1)
COD radeon problems (0)
Browsers wont load websites (4)
Unallocated Space (3)
Size after cutting 700Mb file is 2.5 .. (1)
Blackberry Bold 9000 (0)
Can't open Word (13)
Rar volume (number 7) (1)
System restore :) (1)
Laptop with wireless problem. (14)
Looking for new motherboard (2)
add ram to existing (4)
EVGA 9800 gtx help with finding a goo.. (13)
"Documents and Settings" fo.. (7)
Delete an OS (18)


All times are GMT -4. The time now is 06:49 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28