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
Program for Memory Optimization of C / OpenCL Code Project Description: This is possibly a very simple project for someone with an excellent knowledge of C and OpenCL. That,

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

Program is to read the characters from keyboard: Program is to read the characters from keyboard one by one stored in different files as upper constants, lower constants, othe

I have an exercise with 2 problems. One that is partially completed except with read problems with memory overwrite, and the other problem. I have enclosed the instructions documen

Write a program that computes the cost of a long distance call. The cost of the call is determined according to the following rate schedules. a. A call made between 8:00 AM and 6:


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

Create an applet that bounces a blue ball inside an applet using Thread. The ball (diameter is 10) will start at position (0,0). When the ball hits the edge of the applet, the ba

#include #include #include void* memorycopy (void *des, const void *src, size_t count) {   size_t n = (count + 7) / 8;   char* destination = (char *) des;   char* source =

write a program in c car booking system