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
develop a program read the following information from the keyboard in which base class consist of employee name code and destingnation the derived class contain the data members th

Prepare an Application in C# or C++ Project Description: We are seeking someone who can write a program in C# or C++. The idea is to prepare the program using a Cross Plat

Program is to check whether the string entered is a palindrome or not: Program is to check whether the string entered is a palindrome or not invoke function from main int p

what will be the c program for ideal gas equation.

1.jewels can only be removed for polishing from either end of the necklace. 2.cost of polishing=sitting number*colour value of jewels.

What are Arrays? Numerous applications require the processing of multiple data items that have identical characteristics. In such circumstances it is frequently convenient to p

T o k e n :  Tokens  are  small  entities  in  a  program.    Example: identifiers,  keywords,  constants, operators, strings, etc.  These tokens are used almost in same wa

Write a program which incorporates a function named compute and which is used to calculate the area and circumference of a circle. Use the main function for inputs and outputs.

A: Using the extern "C" linkage specification around the C function declarations. Programmers must know about mangled function names and type-safe linkages. After that they must

F u nction Returning Object: This program is like to the previous program except the function returns object.  The main rule to be remembered is the function returning obj