Re: Function Problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



And the whole thing is non-Unicode, which may (or may not) be a problem.

--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate


"Bruce Eitman (eMVP)" <beitmannospam@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:O2de65ATFHA.548@xxxxxxxxxxxxxxxxxxxxxxx
> 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
>>
>>
>
>


.



Relevant Pages

  • Re: initializing table of strings
    ... >sense to set strings in decleration. ... The fact that it is an array of pointers to const char does not matter ...
    (alt.comp.lang.learn.c-cpp)
  • Re: pointer question (pretty basic)...
    ... Needn't I initialize the pointers first? ... to point to two strings stored somewhere else. ... you'd have been better to use const char ... *pThing instead of char *pThing. ...
    (comp.lang.c)
  • RE: Re: What does "*" mean in "int main(int argc, char *argv[])"?
    ... char arrays (strings). ... "char *argv" says it all as you stated. ... It is a pointer to an array of pointers to nul-terminated ...
    (alt.comp.lang.learn.c-cpp)
  • Re: CompareWithoutRegardToCase
    ... > Returns true if strings are identical, returns false if strings are not ... (without regard to case). ... bool CompareWithoutRegardToCase (char x, char y) ... // Undefined behaviour if supplied with null pointers ...
    (comp.lang.cpp)
  • Re: A taxonomy of types
    ... however, elsewhere in my project (off in the dynamic typesystem, ...), I ... (since I am using NULL-terminated strings), and so I have used U+10FFFF ... remember, C also has things like arrays, funtion pointers, nestable ... int RIL_TypeSmallIntP; ...
    (comp.lang.misc)