Using Character Arrays

All of the examples in this chapter have used numeric arrays, but arrays can also store characters (which, yes, are technically integers). By creating an array of characters, you can create a string. This concept was introduced back in Chapter 2 but merits a review.

There are two important differences between character arrays and other array types. First, storing a string in a character array always requires an extra element. This extra, final element stores the terminating NULL character (\0), which marks the end of a string. Table 6.2 lists the elements for a character array called name with a value of Aubrey.

Table 6.2. A string stored in a character array is actually multiple individual characters terminated by the ...

Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.

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