Wednesday, 16 April 2014

Program to Replace a Character in a String.

/*Write a function strreplace(s,chr,repl_chr) which will replace each occurrences of character chr with the character repl_chr in the string s. The function returns the number of replacements.*/

int strreplace(char [],char,char);
 char s[160],c,r;
 int i;
 printf("Enter any string \(word or sentence\).\n");

 printf("\nYou enter the following string:\n");
 printf("\nEnter the character you want to replace. -> ");
 printf("\nEnter the character you want to insert. -> ");
 printf("\nYou entered \"%c\" to replace with \"%c\".",c,r);
 printf("\nAfter replacement, new string is :\n");
 printf("\nThe total number of replacements is %d.",i);
int strreplace(char s[],char chr,char repl_chr)
 int c=0,i;
 return c;

String Character Replacement C Program's Output

No comments:

Post a Comment