Write a function which takes two string variables (not C strings) as inputs and
ID: 3628049 • Letter: W
Question
Write a function which takes two string variables (not C strings) as inputs and compares them. If they are equal, the function should return 0. If the first string is less than the second string, return a negative number. If the first string is greater than the second string, return a positive number. You are not allowed to use the compare method of the string data type. You must use the comparison operators. Do not write a main function. Your function does not do any cin or cout. Make sure to properly format all your code.Explanation / Answer
int compare(char str1[],char str2[]) { int c1,c2; c1=0; c2=0; while(str1[i]!='') { c1++; } while(str2[i]!='') { c2++; } if(c1==c2) return 0; else if(c1Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.