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
Define Pure Virtual Function? Why & when it is used?

I want MODI method''s coding in c++ using all concepts of c++..please help me its my project work...

search words from a passage and return snippets in html format..

how we can code in c++ for assignment problem (operation research) method to mkinimization and mamization

Write out pseudocode for a function called "and" that takes two arguments, both booleans, and returns the logical and of the inputs. DO NOT use the logical and operator: instead, w

Explain each of the algorithms in a way that would be understandable to an intelligent person who is not familiar with programming. You should not use any code (or even pseudo code



A: Depends. Might be "zero" Objects which are thrown must have a publicly accessible copy-constructor. The compiler is permitted to generate code which copies the thrown object

A Network of routers have been configured for the purposes of handling data traffic within your company. You would like to have an application that does a network