Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions

Question

explain the concept of strategy formulation

Answered: 1 week ago