Write a program to replace one character with another in a given string.
#include<stdio.h> void Replace_char(char*,char,char); int main() { char s[50],a,b; printf("Enter String = "); scanf("%[^\n]",s); printf("Enter character to find = "); scanf(" %c",&a); printf("Enter character to replace with = "); scanf(" %c",&b); Replace_char(s,a,b); printf("String = %s\n",s); return 0; } void Replace_char(char*p,char f,char r) { int i; for(i = 0;p[i];i++) { if(p[i] == f) p[i] = r; } }
Output
Enter String = iotToiearn Enter character to find = i Enter character to replace with = L String = LotToLearn