Listing 12 Slightly cleaner versions of the str::cat function in Listing 11.

//
// append a nul-terminated string to a str
//
void str::cat(const char *s)
   {
   len += strlen(s);
   char *p = strcpy(new char[len + 1], ptr);
   strcat(p, s);
   delete [] ptr;
   ptr = p;
   }

//
// append a str to a str
//
void str::cat(const str &s)
   {
   len += s.len;
   char *p = strcpy(new char[len + 1], ptr);
   strcat(p, s.ptr);
   delete [] ptr;
   ptr = p;
   }

// End of File