Section 21.5 String Practice
Have you ever wondered how to store a bunch of names in an array? You’d need an array of strings. But each string on its own is already an array of characters. Yikes! You’d therefore need an array of arrays! This sounds rather complicated but now we actually have all of the tools needed to do so. Before embarking on the array of strings challenge, let’s quickly review strings on their own. Please pick and solve at least one of the following problems:
Subsection 21.5.1 Option 1
Activity 21.3.
Write a C program with a function printString()
that takes a string (i.e. a char *
) as an argument and prints the string, with individual characters separated by spaces. Here is an example:
printString("chocolate");
should print
c h o c o l a t e
and
printString("I love chocolate!");
should print
I l o v e c h o c o l a t e !
admin.....open in new window
When you are done, please paste your code into the code submission box below:
Subsection 21.5.2 Option 2
Activity 21.4.
Write a C program with a function countWords()
that takes a string as an input parameter and returns the number of words in the string.
For example,
countWords("Today is Wednesday!");
should return the number 3.
admin.....open in new window
When you are done, please paste your code into the code submission box below: