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

Write a function to implement a letter substitution algorithm. Use the following

ID: 3530744 • Letter: W

Question

Write a function to implement a letter substitution algorithm. Use the following prototype for your function: char *substitute( char *input, char *key, char *value ); Where input, key, and value are a zero terminated strings that are input to the function. The first argument, input, contains the string to be transformed. The second argument, key, contains a list of characters for which substitution is required. And the third argument, value, contains the values which are to be substitutes. Suppose that input[i] equals key[j], then output[i] should be set to value[j]. If a value of input is not contained in key then it should be output without substitution.

Explanation / Answer

char *substitute( char *input, char *key, char *value ) { int i=0,j,k=0 char *output; while(input[k]!='') k++; output=(char*)malloc(k*sizeof(char)); while(input[i++]!='') { j=0; while(key[j++]!='') { if(input[i]==key[j]) output[i]=value[j]; else output[i]=input[i]; } } return output; } // Let me know if it shows some error and tell the error too !! Will correct it !! :) :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote