O'Reilly logo

Beginning Programming with C++ For Dummies® by Nat Coalson

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 16. Arrays with Character

In This Chapter

  • Introducing the null terminated character array

  • Creating an ASCIIZ array variable

  • Examining two example ASCIIZ manipulation programs

  • Reviewing some of the most common built-in ASCIIZ library functions

Chapter 15 introduced the concept of arrays. The example program collected values into an integer array, which was then passed to a function to display and a separate function to average. However, as useful as an array of integers might be, far and away the most common type of array is the character array. Specifically something known as the ASCIIZ character array, which is the subject of this chapter.

The ASCII-Zero Character Array

Arrays have an inherent problem: You can never know by just looking at the array how many values are actually stored in it. Knowing the size of an array is not enough. That tells you how many values the array can hold, not how many it actually does hold. The difference is like the difference between how much gas your car's tank can hold and how much gas it actually has. Even if your tank holds 20 gallons, you still need a gas gauge to tell you how much is in it.

For a specific example, the ArrayDemo program in Chapter 15 allocated enough room in nScores for 100 integers, but that doesn't mean the user actually entered that many. He might have entered a lot fewer.

There are essentially two ways of keeping track of the amount of data in an array:

  • Keep a count of the number of values in a separate int variable. This ...

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