O'Reilly logo

Mastering Arduino by Jon Hoffman

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

Character arrays

We saw earlier in this chapter that we can use the character (char) type to store a single character; however, what if we wanted to store whole words or sentences? We can use an array of characters to do this. Character arrays can be initiated exactly like other arrays as the following code shows:

char myStr[10]; 
char myStr[8] = {'A', 'r', 'd', 'u', 'i', 'n', 'o', '\0'}; 

Generally, character arrays are called strings. In the preceding code, we define an uninitialized string that can contain up to ten characters and also a character array that contains the word Arduino.

You may notice that at the end of the Arduino string there is a \0 character. This character represents a null. When defining a string we should always terminate ...

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