Tim Astle wrote:

> Thanks for the tip.  I changed my code around to match your suggestion, but
> the problem still exists.
>
> Here is the code segment I neglected to insert last time.  It's been changed
> though, according to your very valid point :-)
>
> void GetDecFromString(CharPtr str, decNumPtr result)
> {
>      CharPtr temp = MemPtrNew(StrLen(str) + 1);
>
>      int num = 0, dec = 0;
>      Int16 j = 0, k = 0;
>      temp[0] = '\0';
>
>      // Transfer string until the end or '.'
>      while((str[j] != '\0') && (str[j] != '.'))
>      {
>           temp[k] = str[j]; // Get whole number
>           j++;
>           k++;
>      }
>
>      // Increment past the '.'
>      if(str[j] == '.')
>           j++;
>
>      // If there is a continuation after the string '.'
>      while(str[j] != '\0')
>      {
>           temp[k] = str[j];
>           j++;
>           k++;
>           // Keep track of how many numbers after decimal
>           dec++;
>      }
>
>      // Terminate second string
>      temp[k] = '\0';
>
>      MemPtrFree(temp);
>

Beep!!!

>
>      // Convert the strings to an integer
>      num = StrAToI(temp);

You freed this up at the beep!!!  Maybe move the MemPtrFree down here?

>
>
>      // Assign segments to correct parts of structure
>      result->num = num;
>      result->dec = dec;
> }
>
> --
>
> Tim Astle
>
> Roger Chaplin <[EMAIL PROTECTED]> wrote in message
> news:9387@palm-dev-forum...
> >
> > In reply to "Tim Astle" <[EMAIL PROTECTED]>:
> >
> > The return type of your GetDecFromString is decNum *. Although you
> > don't show us the source to GetDecFromString, I'll bet it has an
> > automatic (stack) variable of type decNum, and returns the address of
> > it. This is, in general, a Bad Thing (tm).
> >
> > Again, you didn't show us, so I'm just speculating. If, however, this
> > is the case, here is how you fix it:
> >
> > Change GetDecFromString to this:
> > void GetDecFromString(CharPtr string, decNumPtr result);
> >
> > Make other changes as shown below:
> >
> > > // This is my decimal structure
> > > typedef struct
> > > {
> > >      UInt num;
> > >      UInt dec;
> > > } decNum, *decNumPtr;
> > >
> > >
> > >
> > > CharPtr AddDecimals(CharPtr str1, CharPtr str2, UInt places)
> > > {
> > >      // Need to integrate limited decimal places in string
> > >      // Rounding as well...
> > >
> > >      decNumPtr dec1, dec2;
> > this should be:
> >        decNum dec1, dec2;
> > >      UInt d, result, length;
> > >      int x = 0, i = 0, j = 0;
> > >      CharPtr lstr, strResult;
> > >
> > >      // Get Decimal structure from Strings
> > >      dec1 = GetDecFromString(str1);
> > >      dec2 = GetDecFromString(str2);
> > these two change to:
> >        GetDecFromString(str1, &dec1);
> >        GetDecFromString(str2, &dec2);
> >        // from here on out, dec-> becomes dec. (you get the idea)
> > >
> > >      // Find difference of decimals
> > >      d = dec1->dec - dec2->dec;
> >        d = dec1.dec - dec2.dec;
> >
> > [ the rest deleted ]
> >
> > --
> > Roger Chaplin
> > <[EMAIL PROTECTED]>
> >
> >
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe, please see 
>http://www.palm.com/devzone/mailinglists.html


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to