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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stumped - Functions - working with Doubles 1

Status
Not open for further replies.

jamez05

Programmer
Jul 29, 2005
130
US
I've tried numerous ways to try to pass a double to a function and gets its value back with no success:

My main function declares the following variables and prototype for the function pkaden:
Code:
char ErrorMsg[150];
char s[MAX_SMI];
double PKA;
int pkaden(char *,char *,double);
char CF_PKA[150];
I want the function to return a 1 if no errors along with the an errorMsg or a PKA value. Here's the call in my main function. I'm using a Coldfusion API, so that's what the p-request is about:
Code:
CF_PKA[0] = '\0';
if (pkaden(s,ErrorMsg,PKA)) {
  sprintf(CF_PKA,"%f",PKA);
}
else {
  strcpy(CF_PKA,ErrorMsg);
}
pRequest->SetVariable("CF_PKA",CF_PKA);

in my pkaden function, I set PKA = 1000 for testing purposes. However, after I check it following the function call in my main page, it doesn't change value and is still set to -99.0

Can anyone help me? Not sure what I'm doing wrong.
 
Sorry, there's an error in my above example. Where I declare PKA, it should read
Code:
double PKA = -99.0;
 
If you want a function to change the value of a parameter, you must pass the parameter by reference. The easiest way to do this is, well, to pass it by reference:
Code:
int pkaden(char *,char *,double &);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top