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!

Troubles Passing Argument 1

Status
Not open for further replies.

jamez05

Programmer
Jul 29, 2005
130
0
0
US
I'm using Visual Studio 2005 C++.

One of my cpp pages is named PKADEN.CPP. It contains a funtion named pkaden that calls a function named ev_num which returns a count back to pkaden. Ev_num is found in EVAL.CPP. This works fine, but I need to adjust these functions so ev_num passes a pointer to a linked_list back to PKADEN as well.

PKADEN - I'm not sure what I need to declare and how to pass it to ev_num.

ev_num - I get confused because there are global variables involved. Below is the code. I believe I want to pass *Saved back to PKADEN, but I'm not sure if this is right or if it is, how to do it:
EVAL.CPP:
Code:
/* Defined types and constants */
   static struct alist { /*  Nodes of linked list: Paths */
   int *p;                    /*  Array of paths */
   struct alist *Next;        /*  Next path */
};
/* Global variables */
static struct alist **Saved;        /* Saved paths */

/*Ev_num calls a function that adjusts the struct alist.  I'm able to write the information I need to a file from this funtion, but want to pass this back to PKADEN instead.  Believe it has something to do with *Saved*/
int EV_Num(char *s, MOLECULE *m, RINGS *r)
{
   int i;
   int K_Frag, K_Chem;

   if ( f == NULL ) {
      if ( (f = InitMol()) == NULL ) {
         return( -24 );
      }
   }

   if ( (i = InSmi( s, f, &K_Frag, 1 )) != 0 )
      return( 0 - i );

   /* Make some initial checks to avoid path searches, if possible */

   K_Frag = f->N_Bonds - f->N_Atoms;
   K_Chem = m->N_Bonds - m->N_Atoms;
   if ( f->N_Atoms > m->N_Atoms || f->N_Bonds > m->N_Bonds ) return( 0 );
   if ( K_Frag > K_Chem ) return( 0 );

   /* Fragment could exist, look for it */

   N_Frag = 0;
   StackNull();
   Max_Level = SetSearchPath();
   for ( i = 0; i < m->N_Atoms; i++ ) Visited[i] = FALSE;

   /*  Always try to avoid search if possible */

   if ( (K_Chem = InitStartList( m, r )) == 0 ) return( 0 );

   /* Too bad, must do search */
	//allocate a new node
	Saved =  (struct alist **) malloc(sizeof(struct alist*));   
   *Saved = (struct alist *)NULL;    /* Linked list of saved paths */

   GetPath( m, r );                  /* Get the paths */

   /*New, added by JFN, pass the unique atom IDs for the fragment found. Below is what I want to do in PKADEN  
    struct alist *t;

   ofstream myfile;
   myfile.open ("c:\\pkatest\\Pattern.txt");
	
    while ( *Saved != NULL ) {
       t = *Saved;
		myfile << "Got Here\n";	
		for ( i = 0; i < Max_Level; i++ ){	   
			myfile << t->p[i];    
		}
	   *Saved = t->Next;
       
    }
	myfile.close();
   RemoveAllStack();
   DeletePath(); used to be here.  However, need to use the paths for new PKA program yet, 
   so moving DeletePath()*/

   return( N_Frag);
}
 
I'm not 100% sure what you're trying to do, but if you want to return *Saved instead of the int, change the function to:
Code:
alist* EV_Num(char *s, MOLECULE *m, RINGS *r)
{
   ...
   return *Saved;
}

If you want to return *Saved AND the int back, you'll need to pass one of them by reference...
Code:
int EV_Num(char *s, MOLECULE *m, RINGS *r, alist* pLinkList)
{
   ...
}

Although, if **Saved is a global variable, I don't really see the point in returning it, since everything can access it anyways?
 
Thanks for the reply (I'm close). I'm trying to pass Saved and int back. However, I'm still a little confused on what to declare/do in pkaden:

EVAL.CPP:
Code:
int EV_Num(char *s, MOLECULE *m, RINGS *r, alist* pLinkList)
{
   ...
}

PKADEN.CPP:
Code:
char PKAGroupName[500];
char PKAGroupFrag[500];
MOLECULE *m = NULL;
RINGS r; 

/*Not sure what to do here. Not sure what I need to pass
to EV_Num to get *Saved here*/

N_Frag = EV_Num(PKAGroupFrag, m, &r);
 
This should go into a header, not a .cpp:
Code:
   static struct alist { /*  Nodes of linked list: Paths */
   int *p;                    /*  Array of paths */
   struct alist *Next;        /*  Next path */
};

Then you can include that header and do:
Code:
alist* pSaved = NULL;
N_Frag = EV_Num( PKAGroupFrag, m, &r, pSaved );
 
Thanks cpjust,

However, I'm still getting an error when I try to compile:
Code:
pkaden.cpp(117) : error C2660: 'EV_Num' : function does not take 4 arguments

This is odd because EV_Num has four arguments. Here's what I've done:

1. Moved struct alist to header file as suggested.
2. changed the call to EV_Num to:
Code:
alist* pSaved = NULL;
N_Frag = EV_Num(PKAGroupFrag, m, &r, pSaved);
3. Changed the EV_Num function to:
Code:
int EV_Num(char *s, MOLECULE *m, RINGS *r, alist* pLinkList)

Not sure why this is erroring out?
 
Did you change the EV_Num() function prototype in the header also (i.e. EVAL.h), or just in the .cpp file?
 
Thanks!

The prototype function was hiding in a header named "Smiles.h". Added it there and its compiling now.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top