Write Function Substitutes Occurrences Character Character Str Make Sure Using Pointers C Q37219070

//Write a function that substitutes all the occurrences of the”from” character with the “to” character in str. Make sure usingonly pointers. (C language)
char* substitute(char *str, char from, char to)


Answer


char *substitute(char *str, char from, char to) { char *ptr = str; while (*ptr) { if (*ptr == from) { *ptr = to; } ptr++; }

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.