Shawn,
    The problem is that you have forgotten about the terminating NULL
character.  You have reserved 9 bytes for your string and StrPad has filled
all 9 bytes with '000001234' leaving no space for your NULL char, hence
whatever is after your cTest[] buffer seems to be appended (the CR which is
just as randomly followed by a NULL).  You need to make your cTest[] buffer
10 bytes long (or n + 1) and make sure that any string functions you write
are aware of the fact they should (or in some cases should not) be appending
a NULL terminator.

There are better ways of padding a string, you dont need to allocate
temporary handle's to copy an array of '0's to the front of a string, a
quick 'for' loop will do a much better job.


---------------------------
Steve Fillingham
CodeDrive Pty Ltd
[EMAIL PROTECTED]

"Shawn Fisher" <[EMAIL PROTECTED]> wrote in message
news:31269@palm-dev-forum...
>
> 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