Question: In C++ code Define a function with the prototype below: int compare (char s[], char t[]); The compare function returns 0 if the two C-strings
In C++ code

Define a function with the prototype below: int compare (char s[], char t[]); The compare function returns 0 if the two C-strings are equal, 1 if s is lexicographically less than t and 1 if s is lexicographically greater than t. sult should be returned. Note: compare is essentially the strcmp functions you've been using in the other exercises. The purpose of this exercise is to learn how that fun is implemented. For example, if s is "abc" and t is "abd" then the function would return 1 since the first mismatch is the 'c' for s and the ' d ' for t and of course ' c ' is less than ' d ' as an ASCII character. Special cases: If the strings match up to the respective null terminators, the the string is longer than the other, then the first mismatch will occur when we hit the null terminator of the shorter string. In that case we still can compare ASCII values to determine which string is bigger since the null terminator has ASCII value 0 and the other string wave a corresponding character with some positive ASCII value
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
