Using Character Strings

A more complex version of characters is the character string. Unlike strings you might have used in other programming languages, character strings are a sequence of individual characters.

The easiest way to create a character string is

char name[] = "David Brent";

This will create a variable called name, which contains the string David Brent. However, because character strings must end with the \0 character (which is the NULL character), name actually contains 12 characters.

Chapter 11 will discuss strings in all their glory. In the meantime, let's quickly add and print a character string in our working example.

To work with character strings

1.
Open var4.c (Script 2.4) in your text editor or IDE.
2.
After declaring ...

Get C Programming: Visual Quickstart Guide 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.