Challenge

Write a function called spaceCount() that counts the space characters (ASCII 0x20) in a C string. Test it like this:

#​i​n​c​l​u​d​e​ ​<​s​t​d​i​o​.​h​>​

i​n​t​ ​m​a​i​n​ ​(​i​n​t​ ​a​r​g​c​,​ ​c​o​n​s​t​ ​c​h​a​r​ ​*​ ​a​r​g​v​[​]​)​
{​

 ​ ​ ​ ​c​o​n​s​t​ ​c​h​a​r​ ​*​s​e​n​t​e​n​c​e​ ​=​ ​"​H​e​ ​w​a​s​ ​n​o​t​ ​i​n​ ​t​h​e​ ​c​a​b​ ​a​t​ ​t​h​e​ ​t​i​m​e​.​"​;​
 ​ ​ ​ ​p​r​i​n​t​f​(​"​\​"​%​s​\​"​ ​h​a​s​ ​%​d​ ​s​p​a​c​e​s​\​n​"​,​ ​s​e​n​t​e​n​c​e​,​ ​s​p​a​c​e​C​o​u​n​t​(​s​e​n​t​e​n​c​e​)​)​;​

 ​ ​ ​ ​r​e​t​u​r​n​ ​0​;​
}​

Remember: when you run into '\0', you have reached the end of the string!

Get Objective-C Programming: The Big Nerd Ranch 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.