Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. The strcmp function is one function that is available forthe comparison of st

ID: 3619244 • Letter: 1

Question

1. The strcmp function is one function that is available forthe comparison of strings. However, it provides very limitedinformation about how the string actually compare. (It simplyreturns the relative direction of one string to another.) Youare to rewrite the strcmp function to provide more detail. The minimum requirements for your strcmp function should be,

·          Itshould return a float value, NOT AN ARRAY, that expresses both therelative direction and distance of the second string in relation tothe first string. The first element should have a weight of1, the second element should have weight 1/26, and so on. Asan example, if the strings are “abc” and“bbc”, the function should return 1. If thestrings are “abc” and “zbc”, the functionshould return 25. If the strings are “abz” and“abc”, the function should return -.0325. Thevalue returned will never be less than -26 or greater that 26.

·          Youshould input the number of elements from the string that you wantto compare. If this number is larger than either of thestrings, you should limit the comparison to only the minimum of thetwo string lengths.

·          Yourfunction should ignore the case of the letter and stop thecomparison at the first punctuation mark or when the NULL characteris found.

·          Youmay use the strcmp function within your function.

Explanation / Answer

please rate - thanks #include #include float compare(char[],char[],int); int main() {char s1[50],s2[50]; float value; int n; printf("Enter first string: "); gets(s1); printf("Enter second string: "); gets(s2); printf("How many characters to compare: "); scanf("%d",&n); value=compare(s1,s2,n); printf("when %s and %s are compared, the value is%f ",s1,s2,value); getch(); return 0; } float compare (char s1[],char s2[],int n) {int i; float val=0,wt=1; if(n>strlen(s1))     n=strlen(s1); if(n>strlen(s2))      n=strlen(s2); for(i=0;i