Hello everyone,

I seem to be running into a bit of a problem with a simple MemMove.  All I
am trying to do is add a couple of '0'(zero)s to a string, but what seems to
happen is when I hit the second MemMove, it appends a '\n'(CR) to the end of
the string, and the function StrPad returns a 10 instead of 9.  The
CodeWarrior debugger lists the variable s as "000001234\n" both inside and
outside StrPad.

I am still new to the MemPtr/MemHandle stuff, and any help would be
appreciated.

PS.  I have been using POSE Version 3.0a7, when I use the Palm, it works
except for the first MemSet, which puts random garbage at the end of pText.

Thanks,
Shawn

<Code------------------------------------------------------------------->
DWord PilotMain( Word cmd, Ptr cmdPBP, Word launchFlags )
{
        Err error;
        char cTest[ 9 ] = "1234";
        SWord cTemp;

        cTemp = StrPad( cTest, 9 );
.
.
.
        return 0;
}

SWord StrPad( CharPtr s, UInt dMaxLen )
{
        Err error;
        CharPtr pText = MemPtrNew( dMaxLen );

        if ( pText )
        {
                MemSet( pText, dMaxLen, '0' );
                MemMove( pText + ( dMaxLen - StrLen( s ) ), s, StrLen( s )
);
                MemMove( s, pText, dMaxLen );
                error = MemPtrUnlock( pText );
                return StrLen( s );     
        }
        else
                return 0;
}
</Code------------------------------------------------------------------>

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to