Thread: Pointer modification

  1. #1
    Registered User
    Join Date
    Mar 2009
    Location
    Bozen
    Posts
    95

    Pointer modification

    If I may ask a related pointers question:

    Code:
    void eQ(List* l, Vertex* v){
    	List* new = malloc(sizeof(List*)); new->v = v;
    	if (l == NULL) l = new;
    	else{
    		List* temp = l;
    		while (temp->next != NULL) temp = temp->next;
    		temp->next = new;
    	}
    }
    void connect(Vertex* v, Vertex* u){
    	int i = vIndex(v); int j = vIndex(u);
    	AC[i][j] = 1; AC[j][i] = 1;
    	eQ(v->adj, u); eQ(u->adj, v);
    }
    Now unfortunately exiting eq(..) v->adj and u->adj remain unchanged pointing to null. I know of the solution: v->adj = eQ(v->adj, u) but I'd like to get the 'pointers' solution to work as well. Could someone suggest the code modifications to make to achieve that?

    PS: The structures referred to here are posted in my other thread of the day 'Deadlock prevention in C'

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    By passing the the address of &v->adj and &u->adj to eQ().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 03:47 PM
  2. Replies: 1
    Last Post: 03-24-2008, 10:16 AM
  3. Parameter passing with pointer to pointer
    By notsure in forum C++ Programming
    Replies: 15
    Last Post: 08-12-2006, 07:12 AM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM