Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 valueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started