70 likes | 195 Views
One Stop Programming . Cap-Stone Project. C ++ Beginner Tutorial 10. Null Terminated Strings. String “Hello World” in memory: Note the last character is ’ ’. This indicates the end of the string in memory and must be factored into the size of the array.
E N D
One Stop Programming Cap-Stone Project C++ Beginner Tutorial 10
Null Terminated Strings • String “Hello World” in memory: • Note the last character is ’\0’. This indicates the end of the string in memory and must be factored into the size of the array. • The length of the string “Hello World” is 11 characters. However, this size is 12. Make sure to accommodate this when building your functions. • It is possible to check if the character at an index is a null termination character. Ex: if(str[3] == ‘\0’).
Cap-Stone Project Develop the three functions below according to each of their requirements. A template file is provided to help you get started: • intcountChar(char str[]) • Counts the number of characters in a string. Does not include null termination character. • Example: “hi” has 2 characters, “The dog.” has 6 characters, and “” has zero characters. • void removeSpaces(char str[]) • Removes spaces from a string and then prints the string with no spaces. • Example: “Hello world” prints “HelloWorld” • void reverseChar(char str[]) • Prints the string backwards starting from the last character in the string. • Example: “The red fox” prints “xof der ehT”
Template And Solution Provided • Download the template and solution from: http://onestopprogramming.com/blog/?page_id=2