//UPDATED VERSION..Minor changes in delete and insert functions.. // Input three strings s, t and w from the user. Assume that the strings do not // contain blank or any whitespace character.Write a function that finds all occurrences // of substring t in s, and replaces them by w. The function returns the number // of such occurences or replacements.Note that t and w can be of different sizes. //Author:rahule@cse.iitk.ac.in #include int replace_substring(char *, char *, char *); void delete(char *,int ,int); void insert(char *,char * ,int); int string_length(char *); main() { char t[50],s[50],w[50]; int cnt; //entering the strings printf("\nEnter the string S :"); scanf("%s",s); printf("\nEnter the string t :"); scanf("%s",t); printf("\nEnter the string w :"); scanf("%s",w); //calling the function cnt= replace_substring(s,t, w); printf("\n%d number of instances were found and replaced..\nThe new string is :'%s\n'",cnt,s); } int replace_substring(char *s, char *t, char *w) /*function accepts three strings s t w and replaces all the instances of t in s with w */ { int k,j,cnt=0,flag; for(j=0;j< (string_length(s) - string_length(t)) ;j++) { flag=0; for(k=0;k=index;j--) //makes room for w by shifting all the lements starting from 'index' by an offset "length(w)" to right s[j+l]=s[j]; for(j=0;j