Hi Chris,
you define
Char CustNo [5];
and set
r.CustNo[5] = chrNull;
to terminate the string. But the string has a length of 5, so the indices are
0..4, not 0..5. You set the chrNull as the first character of the next field,
so it's overwritten in the next step. Use r.CustNo[4] = chrNull; etc instead.
Greetings
Helmut
Am Mittwoch, 19. Mai 2004 18:11 schrieb Chris Hall:
> I have written some code to load some data into the handheld for testing
> purposes. I am trying to mimic a situation where I will be reading in a
> fixed record and writing the data as strings into individual database
> fields. When I watch this process thru the emulator, I am confused at the
> string lengths it is telling me that I have for each field.
>
> For example, the CustNo should be a string with length of 5..... the
> emulator says it has length 73. What have I missed here? And is there a
> better way to do this?
>
> Thanks so much
> Chris
>
>
>
> //----------------------------------------------------------
> // Customer Database Structure
> //----------------------------------------------------------
> typedef struct customerDB {
> Char CustNo [5];
> Char CustLoc[5];
[...]
> } customerDB;
>
> Boolean UpdateCustomerDB(Char rec[])
> {
> extern DmOpenRef gcustomerDB;
>
> Err error;
> UInt16 index = 0;
> MemHandle h;
> customerDB r; // this is the database record
> Char *strPcnt;
> Int32 iPcnt;
> UInt16 len;
>
> // fill the record with data
> if (rec[0] == 'A')
> {
> rec += 1;
> StrNCopy(r.CustNo,rec,5);
> r.CustNo[5] = chrNull;
> rec += 5;
> StrNCopy(r.CustLoc,rec,5);
> r.CustLoc[5] = chrNull;
[...]
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/