Question: Write a function called strcmp373 in C. This function is passed two parameters, both of which are C strings. You should use array syntax when

Write a function called strcmp373 in C. This function is passed two parameters, both of which are C strings. You should use array syntax when writing this function; that is, you may use [ ], but not * or &. The function should return an int as follows:

A negative number if the first string is alphabetically before the second string. In C, the return value of strcmp is a number which reflects the difference in the ASCII codes for the first 2 letters which are not the same. For example, a call to strcmp("programming", "project") returns -3, since 'g' and 'j' in ASCII differ by 3.

Zero if the strings are the same

A positive number if the second string is alphabetically before the

first string. Again, the number is the difference in ASCII codes between the first 2 letters which are not the same.

Here are some additional examples from the built-in C strcmp function:

strcmp("bin", "bag"); // returns 8 strcmp("computer", "game");//returns-4 strcmp("computer", "computer");//returns0 strcmp("are", "area"); /* returns -97, because '\0'- a = 0-97 = -97.

Your strcmp373 function should emulate strcmp in this way; in other words, if the return value is not zero, the value of the negative or positive integer should reflect the difference in the ASCII encoding of the first differing letters in the two strings.

int strcmp373(char str1[], char str2[]) {

return 0; // replace this

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!