/*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

No data
He led the Lightning with 17 points in 17 playoff games last season, and his 58 postseason Wholesale ...
No data
No data
No data
Looks like it's going to take more than a well-enforced curfew to help this team pick up some ...
No data
No data
No data
Residents selected to purchase tickets this year will receive Mobile Ticketing instructions along ...
No data
No data

Leave a Reply

Your email address will not be published. Required fields are marked *

Skip to toolbar