Let's look at the struct again:

> > typedef struct MyDBStruct {  // hypothetical fix-sized data record
> >   char   str1[50];
> >   double num1
> >   char   str2[25];
> >   short  num2;
> > } MyDBStruct;

While the lengths of the strings stored in str1
and str2 may be unknown, the -sizes- are known:
50 and 25, respectively.

Now, if "hello" is stored in str1, then it will
look like this:

        'h' 'e' 'l' 'l' 'o' '\0' 'x' 'y' 'z' 'z' 'y'

Where the "xyzzy" may be left over from previous
data stored in str1, or may just be uninitialized
random data (or may all be '\0' if data is initialized
to 0).

If str1 and str2 had been declared as "char *"
instead of character arrays, we'd have a completely
different story & the answer would be a lot more
complex.

But for the record struct under discussion, the
result of "strlen(xxx.str1)" is immaterial.

-- 
-Richard M. Hartman
[EMAIL PROTECTED]

186,000 mi./sec ... not just a good idea, it's the LAW!


> -----Original Message-----
> From: Lenny Palozzi [mailto:[EMAIL PROTECTED]]
> 
> This may have been already answered in this thread, sorry if 
> I missed it.
> 
> What if the lengths of str1 and str2 are not known? How do 
> you then get
> access to num1 and num2(and str2). In some, if not most 
> cases, using fixed
> legnth records would be a waste of valuable space on the 
> Palm. ie. Using 50
> bytes to hold only 5+1(NULL) = 6 of my name "Lenny\0".
> 
> I need to do this in my recordPack/Unpack procedures, and I 
> am trying to
> save space by not using fixed length records.
> 
> Thanks,
> Lenny
> 
> 
> ----------
> > From: Jim Schram <[EMAIL PROTECTED]>
> > To: [EMAIL PROTECTED]
> > Subject: RE: Using DmQuickSort ??
> > Date: Monday, March 22, 1999 5:51 PM
> > 
> > At 2:29 PM -0800 1999/03/22, Michael S. Davis wrote:
> > >Ok, almost got it.  Let's say my compare functions performs
> > >as follows:
> > >
> > >double elem1       // variables within a record
> > >double elem2       // variables within a record
> > >
> > >if(elem1 <  elem2){ return -1 };
> > >if(elem1 == elem2){ return  0 };
> > >if(elem1 >  elem2){ return +1 };
> > >
> > >Now my problem is this.  this is easy if I declare elem1 and elem2
> > >but how do I refer to these as part of the record.
> > 
> > Assuming fixed-sized fields in your records (which allows 
> you to declare
> the record as a C struct) just declare the first two 'void *' 
> pointers as
> pointers to your record struct type and defererence the 
> appropriate member
> using the -> notation, like this:
> > 
> > typedef struct MyDBStruct {  // hypothetical fix-sized data record
> >   char   str1[50];
> >   double num1
> >   char   str2[25];
> >   short  num2;
> > } MyDBStruct;
> > 
> > typedef MyDBStruct* MyDBStructPtr;
> > 
> > Int MyCompareFunc( MyDBStructPtr p1, MyDBStructPtr p2, ...)
> > ...
> >   if ( p1->num1 < p2->num1 ) return -1;
> >   etc.

Reply via email to