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 books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.