Array and Strings – Strings – Problem #13
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
Camel case notation is a special type of typography where multiple different words are combined together as one word without any space in between AND the first letter of each different word is uppercase while the remaining letters are lowercase. For example ‘MySchool’ is a camel case notation consisting of two separate words ‘my’ and ‘school’, while ‘IAmHappy’ is a camel case notation containing three words, ‘I’, ‘am’ and ‘happy’. Now consider the following two functions to perform the tasks as mentioned. • int numberOfWords(char *camel) - takes input a camel case string char *camel as argument and returns the number of constituent words. • void camelToReverse(char *camel, char *reverse) - Takes input two arguments, one camel case string (char *camel) and another empty string (char *reverse). Hence it fills up the empty string with the constituent words of the camel case string in the reverse order (as it appears in the camel case string) with a space in between the constituent words and terminated with null. For example if the camel case string is ‘IAmHappy’, then reverse[ ] will contain ‘Happy Am I’, which is also a null terminated string. Write a C program to input a camel case string containing any number of constituent words. First print the number of constituent words of the input string by calling the appropriate function within main(). Then call the function camelToReverse() to generate the reverse string of the constituent words and print them within that function only. You can assume that the input is always a valid camel case string. Note that you can declare character arrays inside main() for taking the string input and initializing the empty string, BUT you must work with pointers to string within the two functions, i.e while calling the functions you must pass the base address of the character arrays and work with pointers inside the respective functions. You are NOT allowed to use any in-built string functions except probably strlen() ONLY. Example: Input: ‘HowDoYouDo’ Output: Number of words: 4 Reverse string: ‘Do You Do How’ [using pointers] [NOTE the space in between the constituent words]