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];
Char CustName[30];
Char Addr[30];
Char AuthF[1];
Char PriceNo[2];
float DiscPcnt; //4.2
Char Route[3];
Char CallDay[7];
Char DelvDay[7];
} 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;
rec += 5;
StrNCopy(r.CustName,rec,30);
r.CustName[30] = chrNull;
rec += 30;
StrNCopy(r.Addr,rec,30);
r.Addr[30] = chrNull;
rec += 30;
StrNCopy(r.AuthF,rec,1);
r.AuthF[1] = chrNull;
rec += 1;
StrNCopy(r.PriceNo,rec,2);
r.PriceNo[2] = chrNull;
rec += 2;
StrNCopy(strPcnt,rec,4);
strPcnt[4] = chrNull;
iPcnt = StrAToI(strPcnt);
r.DiscPcnt = iPcnt * .01;
*r.Route = chrNull;
*r.CallDay = chrNull;
*r.DelvDay = chrNull;
}
h = DmNewRecord(gcustomerDB, &index, sizeof(r));
if (h)
{ // could fail due to insufficient memory!
MemPtr p = MemHandleLock(h);
error = DmWrite(p, 0, &r, sizeof(r));
MemPtrUnlock(p);
DmReleaseRecord(gcustomerDB, index, true);
}
else
error = DmGetLastErr();
len = StrLen(r.CustNo) ; // ----------------->>>>> Len =
73 in emulator
len = StrLen(r.CustLoc) ; // ----------------->>>>> Len =
68 in emulator
len = StrLen(r.CustName) ; // ----------------->>>>> Len = 63
in emulator
len = StrLen(r.Addr) ; // ----------------->>>>> Len
= 33 in emulator
len = StrLen(r.AuthF) ; // ----------------->>>>> Len
= 3 in emulator
len = StrLen(r.PriceNo) ; // ----------------->>>>> Len =
2 in emulator
len = StrLen(r.Route); // ----------------->>>>> Len
= 0 in emulator
len = StrLen(r.CallDay); // ----------------->>>>> Len
= 0 in emulator
len = StrLen(r.DelvDay); // ----------------->>>>> Len =
0 in emulator
return error;
}
void LoadCustomerFile()
{
int i;
extern DmOpenRef gcustomerDB;
Char rec[5][78] =
{
{"A358034932 RITE AID #4932 E.LEHIGH AVE. 260 WEST LEHIGH AVENUE
Y030250"},
{"A358032564 RITE AID #2564 WYOMING AV 113-131 WEST WYOMING AVENUE
Y030300"},
{"A360031282 CVS # 1282 GREENFIELD AVENUE 44 GREENFIELD AVENUE
Y080000"},
{"A358031758 RITE AID #1758 CLIFTON HGTS 113 E BALTIMORE AVENUE
Y030000"},
{"D358030174 RITE AID #0174 16TH&CHESTNUT 1628-36 CHESTNUT STREET
Y030000"}
};
for (i = 0; i < 5; i++) {
UpdateCustomerDB(rec[i]);
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/