October 1997
Intermediate to advanced
800 pages
20h 48m
English
Character strings (char *) must always have a NULL (\0) terminator. Whether you declare character strings as literals or build one on the fly, you're expected to terminate each string with a NULL byte. This arrangement gives you access to a wide variety of string library functions and lets you input or output strings easily. Suppose, however, you need to handle NULL bytes as data (common in database formats and communications protocols). For example, the statement
const char *p = "\0two nulls\0\n";
allocates 12 bytes of character data (including two NULL bytes). A simple output statement such as
cout << p; // doesn't display the data
fails to display this string properly. Moreover, the string ...