Replace Char In A String C

[Solved] Replace Char In A String C | Swift - Code Explorer | yomemimo.com
Question : replacing a character in string in C

Answered by : troubled-trout-7et5geszy1x1

#include<stdio.h>
#include<conio.h>
main()
{
int i;
char a,b,str[100];
printf("Enter the string");
gets(str);
//asking for replacement
printf("enter the character to be replaced");
scanf("%c",&a);
// which letter to replace the existing one
printf("enter the character to replace");
scanf("%c",&b);
for(i=0;str[i]!='\0';i++)
{ if(str[i]==a) { str[i] = b; } else continue;
}
printf("the new string is");
puts(str);
}

Source : https://stackoverflow.com/questions/27527254/replacing-a-character-in-string-in-c | Last Update : Thu, 14 Jul 22

Answers related to replace char in a string c

Code Explorer Popular Question For Swift