There's no need for \0 (which is getting misinterpretted by your StrPrintF)
in that string. All strings in "'s are automatically null terminated.



Young S. Cho <[EMAIL PROTECTED]> wrote in message
news:37917@palm-dev-forum...
>
> Hi all,
>
> I'm writing simple Palm DB code to write text strings to the database and
> then to read it back. However, when I read the values back, I'm getting
> garbage characters appended to my text string. Now, I'm not sure whether
the
> garbage is getting added at the insert or read, but has anyone seen
> something similar to this?
>
> Thanks for any advice or suggestions...
>
> Young Cho
>
> [EMAIL PROTECTED]
>
> The code fragment looks something like this:
>
> ------- Code to write & read from the DB
>
> // Open the database - my routine to create the DB and to open it
>
> error = OpenDB(appDatabaseName, 'DATA', appCreatorID);
>
> iIndex = WriteDB("Test message1\0", 0);
>
> iIndex = WriteDB("Test message2\0", 1);
>
> for(iIndex = 0;iIndex < GetNumRecords();iIndex++)
>
> {
>
>     record = ReadDB(iIndex);
>
>     StrPrintF(msg, "%2d:[%s]\n", iIndex, record);
>
>     DisplayMessage(msg);
>
> }
>
> error = CloseDB();
>
>
>
> ----- WriteDB looks like this ------
>
> UInt16 WriteDB(char *pText, UInt16 iRecPos)
>
> {
>
> char *pTmpPtr;
>
> Err error;
>
> MemHandle newRecordH;
>
> newRecordH = DmNewRecord(gLibDB, &iRecPos, StrLen(pText));
>
> pTmpPtr = MemHandleLock(newRecordH);
>
> error = DmWrite(pTmpPtr, 0, pText, StrLen(pText));
>
> MemHandleUnlock(newRecordH);
>
> // Unset the record's busy bit
>
> DmReleaseRecord(gLibDB, iRecPos, true);
>
> return(iRecPos);
>
> }
>
>
>
> ----- ReadDB looks like this -----
>
> char * ReadDB(UInt16 iRecPos)
>
> {
>
> Char *pText = NULL;
>
> MemHandle recordH;
>
> static char datatext[1024];
>
> MemSet(&datatext, sizeof(datatext), 0);
>
> recordH = DmQueryRecord(gLibDB, iRecPos);
>
> pText = MemHandleLock(recordH);
>
> StrPrintF(datatext, "%s\0", pText);
>
> MemHandleUnlock(recordH);
>
> return(datatext);
>
> }
>
>
>
>
>



-- 
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