Question: I need help writing the function for this RME in C++ using c-strings! // REQUIRES: str1 and str2 point to C-strings // EFFECTS: If str1

I need help writing the function for this RME in C++ using c-strings!

// REQUIRES: str1 and str2 point to C-strings

// EFFECTS: If str1 and str2 contain exactly the same characters, returns 0.

// Otherwise, return a positive number if the first differing char // has a greater value in str1 than in str2 and a negative number in

// the opposite case (you may NOT call strcmp).

int strcmp(const char *str1, const char *str2)

{ So what I figured is that I have to compare the two strings, assuming they are the same length.

if (str1 == str2) { return 0; }

else { //somehow compare every letter and when the letters at the same index are not equal, return the difference of the letter in str1 - the letter in str2 so if str1 is greater it returns a positive number and a negative one if the differing letter in str1 is smaller than the one in str2. }

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!