O'Reilly logo

Objective-C Programming: The Big Nerd Ranch Guide by Mikey Ward, Aaron Hillegass

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

char *

A C string is just a bunch of characters right next to each other in memory. The string ends when the character 0x00 is encountered.

Figure 39.1  The word “Love” as a C string

The word “Love” as a C string

Functions that take C strings expect the address of the string’s first character. strlen(), for example, will count the number of characters in a string. Try building a string and using strlen() to count the letters:

#​i​n​c​l​u​d​e​ ​<​s​t​d​i​o​.​h​>​ ​ ​/​/​ ​F​o​r​ ​p​r​i​n​t​f​
#​i​n​c​l​u​d​e​ ​<​s​t​d​l​i​b​.​h​>​ ​/​/​ ​F​o​r​ ​m​a​l​l​o​c​/​f​r​e​e​
#​i​n​c​l​u​d​e​ ​<​s​t​r​i​n​g​.​h​>​ ​/​/​ ​F​o​r​ ​s​t​r​l​e​n​ i​n​t​ ​m​a​i​n​ ​(​i​n​t​ ...

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