What is the best practice for string manipulation?
I have a function called Look4Dollars that scans a string for the decimal
point, copys the dollar portion of the string, converts it to an int and
adds it to a total.
when I call it in the following sequence:
Look4Dollars ("3000.00");
Look4Dollars ("100.00");
The resulting total becomes 4000 instead of 3101.
I am stumpped!
/***************************************************************************
*****\
// Global variables
char * dollarsString[6];
char totalDollarsString[8];
Int32 dollars;
Int32 totalDollars;
static void Look4Dollars( char * string)
{
char * decimalPlace;
Int32 dollarLength;
decimalPlace = StrStr(string, ".");
if (decimalPlace != NULL)
{
dollarLength = decimalPlace - string;
StrNCopy(dollarsString, string, dollarLength);
dollars = StrAToI(dollarsString);
totalDollars = totalDollars + dollars;
StrIToA(totalDollarsString, totalDollars);
}
}
/***************************************************************************
*****\
I call the function twice with the following strings:
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/