Chapter 15. Low-Level Strings

C is not a string-processing language per se, but it does include facilities for manipulating arrays of characters, which are commonly called strings. By convention, an N-character string is an array of N+1 characters in which the last character is the null character; that is, it has the value zero.

The language itself has only two features that help process strings. Pointers to characters can be used to traverse character arrays, and string literals can be used to initialize arrays of characters. For example,

   char msg[] = "File not found";

is shorthand for

   char msg[] = { 'F', 'i', 'l', 'e', ' ', 'n', 'o', 't',
       ' ', 'f', 'o', 'u', 'n', 'd', '\0' };

Incidentally, character constants, like 'F', are ints, not chars, which ...

Get C Interfaces and Implementations: Techniques for Creating Reusable Software now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.