Question: 4a) Write a function called compare_strings () that will take two words (i.e. two strings) as parameters. The function compares the two words and displays


4a) Write a function called compare_strings () that will take two words (i.e. two strings) as parameters. The function compares the two words and displays to the screen a combination of dashes '-' and characters. That is, the output will contain dashes '-' where the characters differ (i.e. not the same characters but in the same position) and characters where the characters are the same, i.e. the same character and in the same position. The function counts and returns the number of characters that are the same, that is, the same character and in the same position. Check the lengths of both words to ensure they are the same length before continuing. If the words are not the same length, the function displays a question mark (?) to the screen and returns 0. You must use a loop in your solution. For example: If we pass the words "ipad" and "ipod" to the function compare_strings like so: compare_strings ("ipad", "ipod"); the function should display the string"ibe-d" to the screen and return 3. That is, there are three characters that are the same and in the same position. If we pass the words "same" and "pain" to the function compare_strings like so: compare_strings ("same", "pain"); the function should display the string"-a-" to the screen and return 1. That is, there is only one character that is the same and in the same position. If we pass the words "boring" and "exciting" to the function compare_strings like so: compare_strings ("boring", "exciting"); the function should not display "?" to the screen and return O. That is, the words are different lengths. Given the following variable definitions: char word1[] = "star"; char word2[] = "stop"; int matches = 0; Show how you would call function compare_strings (). Display the words (strings), the resulting string and the value stored in variable matches to the screen as follows: star stop = st-- 2 If you didn't complete part a), you may assume that you did in order to answer this
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
