(a)
bool: ispacked(string[])
      return bool: (string[0] > charmax);

(b) 
strlen(string[])
   {
   new len = 0;
   if (ispacked(string))
       while (string{len} ! '^0')     /* get character from pack */
           ++len;
   else
       while (string[len] ! = '^0')     /* get cell */
           ++len;
   return len;
   }

Example 2: (a) Function that distinguishes packed from unpacked strings; (b) the strlen() function that works on packed and unpacked strings.

Back to Article
Copyright © 1999, Dr. Dobb's Journal