Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Still having Issues Passing a Structure

Status
Not open for further replies.

jamez05

Programmer
Jul 29, 2005
130
0
0
US
I have been able to get my program to compile, but it errors out when I try to run it. I'm trying to pass
a linked-list structure to another function. PKADEN is
the function that needs to recieve "*Saved".

The call to EV_Num from PKADEN:

Code:
alist* pSaved = NULL;
N_Frag = EV_Num(PKAGroupFrag, m, &r,MAXLEV,pSaved);

EV_Num is declared in a header named SMILES.H:

Code:
int EV_Num(char *, MOLECULE *, RINGS *,int& MAXLEV, struct alist *pLinkList);
Additionally, the following struct is delcared in Smiles.h:
Code:
static struct alist {         /*  Nodes of linked list: Paths */
   int *p;                    /*  Array of paths              */
   struct alist *Next;        /*  Next path                   */
};
EV_Num resides in eval.cpp. There is another struct set before the EV_Num function:
Code:
static struct alist **Saved;  /* Saved paths               */

The EV_Num function:
Code:
int EV_Num(char *s, MOLECULE *m, RINGS *r,int& MAXLEV,alist* pLinkList)
{
   int i;
   int K_Frag, K_Chem;
   int *pMAXLEV = &MAXLEV;

//allocate a new node
Saved =  (struct alist **) malloc(sizeof(struct alist*));   
 *Saved = (struct alist *)NULL;    /* Linked list of saved paths */
//GetPath adds nodes to the list
   GetPath( m, r );                  /* Get the paths */
   pLinkList = *Saved;//I've added this, but doesn't work

Here's what I would like to do on PKADEN, but not having any luck, I've trimmed out some code to get more to the point:
Code:
int pkaden(char *s, char *ErrorMsg, char *PKADetail, double& FinalPKA, int ShowDetails)
{
alist* pSaved = NULL;
N_Frag = EV_Num(PKAGroupFrag, m, &r,MAXLEV,pSaved);
 struct alist *t;   
 while ( *pSaved != NULL ) {
     t = *pSaved;	
     myfile << "Got Here\n";	
     for ( i = 0; i < Max_Level; i++ ){	   
       myfile << t->p[i];    
     }
    *pSaved = t->Next;
}
 
jamez05 said:
but it errors out when I try to run it.
What is the error you get?
Do you know what line is causing the error?

Code:
pLinkList = *Saved;//I've added this, but doesn't work
Unless GetPath() modifies *Saved, this line is the same as doing:
Code:
pLinkedList = NULL;

BTW, global variables are evil. :p
 
Thanks for getting back.

I'm pretty sure GetPath() modifies *Saved (it calls a bunch of other functions that check to see if its a unique path. If it is, it adds it to the linked list:

Saved Path =

next-------------->next----------------->next----------------->next = null(=end)
path[Max_Level] path[Max_Level] path[Max_Level] path[Max_Level]


I've playing around with it and changing variables etc..
I'm trying to print the address of *Saved from PKADEN, but
always end up with it being empty. I'm reading a tutorial on pointers right now. I'll try write a more intelligent question in a little bit.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top