/*Program for Replacing a character*/


#include 
#include 

void main()
{
int replace_char(char *,char,char);
char *str;
char old_char,new_char;
int r;
clrscr();
printf("nnnttt Program for Replacing a character");

printf("nnnttt Enter a line of text :");
printf("nnt >> ");

gets(str);

printf("nnt Enter the Character to find = ");
flushall();
scanf("%c",&old_char);

printf("nnt Enter the Character to be replaced = ");
flushall();
scanf("%c",&new_char);

r=replace_char(str,old_char,new_char);

printf("nnnttt Line after replacing the characters :");
printf("nnt >> %s",str);
printf("nnt Total character replaced = %d",r);
getch();
}

int replace_char(char *s,char o,char n)
{
int i,f=0;
for(i=0;s[i]!='';i++)
{
if(s[i]==o)
{
s[i]=n;
f++;
}
}
return(f);
}

Related Posts

आज से विश्व कप का आगाज: रिजर्व-डे से लेकर सुपरओवर तक, 17 पॉइंट्स में जानें इस टूर्नामेंट से जुड़ी हर ...
worldeye
October 6, 2023
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore ...
worldeye
January 23, 2022
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore ...
worldeye
January 23, 2022