O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

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

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

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