C program to replace every occurrence of in a string, C/C++ Programming

Program is to replace every occurrence of in a string:

Program is to replace every occurrence of c1 in string with c2 and have function return the no. of replacement

int replace(char *s,char c1,char c2);

void main()

  {

   clrscr();

   char *s,c1,c2;

   int ans;

   cout<<" enter a string ";

   gets(s);

   cout<<" enter the string to be searched ";

   cin>>c1;

   cout<<" enter the string to be replaced ";

   cin>>c2;

   ans=replace(s,c1,c2);

   cout<<" the no. of replacement made "<

   cout<<" the string after replacement being made :"<

  }

 

int replace (char *s,char c1,char c2)

  {

  int i=0;

  int count=0;

 while(s[i]!= NULL)

    {

    if (s[i]==c1)

      {

     s[i]=c2;

     count++;

      }

     i++;

    }

 return count;

  }

Posted Date: 10/19/2012 7:57:17 AM | Location : United States







Related Discussions:- C program to replace every occurrence of in a string, Assignment Help, Ask Question on C program to replace every occurrence of in a string, Get Answer, Expert's Help, C program to replace every occurrence of in a string Discussions

Write discussion on C program to replace every occurrence of in a string
Your posts are moderated
Related Questions
Which constructor gets called while I create an array of Fred objects?

What about Virtual Destructor? describe it.

C program to demonstrate Pointer to array: void p2a(int *); void main() {                 int x=10, *a,**b;                 int arr[5];                 a=&x;//po

derivations 1. Regardless of the type of derivation, private members are inherited by the derived class, but cannot be accessed by the new member function of the derived class,

padovan string problem program 1 : package test.padovanstring; public class PadovanString {     public int stringOccurrences(int n, String str){        if(n >= 40)

write a program to find the area under the curve y=f(x) between x=a & x=b

Bitwise Operations 1. Write a function that has an int parameter n, makes an integer mask having the bit 1 at the nth place from the rightmost bit, and returns the mask. For ex

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

A: Along with the C++ language, you can overload operators and functions. Overloading is the practice of supplying more than one definition for a provided function name in the same

The code contains two built-in pitfalls. First one, if it executes in a member function for an static, extern or automatic object, the program will possibly crash as soon as the de