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
I hv an assignment to do, I almost done. But i cant find whats wrong- my code is to make a simple calculator using function''s all 4 patterns. I did like this- #include int add

There is a pebble merchant. He sells the pebbles, that are used for shining the floor. His main duty is to take the length of the room’s sides. But he sometimes mistakes doing that


how to create a shopping cart

Define Polymorphism? A: Polymorphism let a client to treat distinct objects in the similar way even if they were developed from distinct classes and exhibit different behaviors.

to count number of occurances

A: C++, unlike only about every other language with exceptions, is extremely accomodating while it comes to what you can throw. Actually, you can throw anything you akin to. That b


To implement a back account system for new users

Your program will read two kinds of data from two files: names and predicates. It will read a formal expression from standard input and check whether that expression is syntactical