Re: Function Problem
- From: "Bruce Eitman \(eMVP\)" <beitmannospam@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 28 Apr 2005 12:22:29 -0400
Helge is correct, you *cannot* return pointers to data on the stack and
expect that the data is valid after the return. Either dynamically allocate
a buffer at runtime or modify the original string.
But you have more problems than that.
Isl_Total takes paramters that are pointer to strings of undefined length,
but fnReplace takes pointers to strings of length 16. This inconsistency
could bite you later on when you least expect it.
See below, error checking and freeing is left to you.
extern "C" void _cdecl Isl_Total(char x[], char y[], char *res)
{
char *s = malloc( strlen(y));
char *t = malloc( strlen(x));
strcpy( s, y );
strcpy( t, x );
fnReplace(s);
fnReplace(t);
double xx =atof( s ), yy= atof( t );
double result;
result = xx + yy;
_gcvt( result, 7, res);
}
///////////////////End/////////////////////////////
////////////////Second Function/////////////////////////
void fnReplace (char *RplStr)
{
char find = ',';
char replace = '.';
char string[16];
int len,i;
len = strlen( RplStr );
for (i=0;i<=len;i++)
{
if ( RplStr[i] == find )
RplStr[i] = replace;
}
}
//////////////////////End/////////////////////////////
--
Bruce Eitman (eMVP)
Senior Engineer
beitman AT applieddata DOT net
Applied Data Systems
www.applieddata.net
An ISO 9001:2000 Registered Company
Microsoft WEP Gold-level Member
"Helge Kruse" <Helge.Kruse-nospam@xxxxxxx> wrote in message
news:%23tdqew$SFHA.3312@xxxxxxxxxxxxxxxxxxxxxxx
> Dont know, what "does not work" means, but...
>
> your function fnReplace returns the address of the auto variable "string".
> That doesn't work.
>
> Regards, Helge
>
>
.
- Follow-Ups:
- Re: Function Problem
- From: Chris Tacke, eMVP
- Re: Function Problem
- References:
- Function Problem
- From: Thrax
- Re: Function Problem
- From: Helge Kruse
- Function Problem
- Prev by Date: Re: retailmsg
- Next by Date: Re: GetFont() not working ...
- Previous by thread: Re: Function Problem
- Next by thread: Re: Function Problem
- Index(es):
Relevant Pages
|