Page 1 of 1

Write a C++ function compStr(s1,s2) which takes two strings, s1 and s2, and compares them. If s1 and s2 are of differen

Posted: Sat May 14, 2022 7:03 pm
by answerhappygod
Write a C++
function compStr(s1,s2) which takes two
strings, s1 and s2, and compares them.
If s1 and s2 are of different lengths, the
function returns –1 if s1 is shorter than s2, or 1
if s2 is shorter than s1.
If s1 and s2 are the same length, the function
returns –1 if s1 comes
before s2 alphabetically, 1 if s2 comes
before s1 alphabetically.
If s1 and s2 are the same string, the function
returns 0. Note: A character value ch1 is alphabetically
before a character value ch2 provided ch1 <
ch2.
Requirements: