O'Reilly logo

C Interfaces and Implementations: Techniques for Creating Reusable Software by David R. Hanson - Princeton University

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required