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

Assignment Help:

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;

  }


Related Discussions:- C program to replace every occurrence of in a string

Random question, Ask question #write statement that assign random integer t...

Ask question #write statement that assign random integer to the varaible n in the (100

Lexicographically preceding permutation, Given an integer n and a permutati...

Given an integer n and a permutation of numbers 1, 2 ... , n-1, n write a program to print the permutation that lexicographically precedes the given input permutation. If the given

All topics in c, Give practice in writing program''s..

Give practice in writing program''s..

Data Handling in computers, though the ascii is called 7-bit code. why do w...

though the ascii is called 7-bit code. why do we use 8-bits to represent a character?

Load catalogue from file, Implement a menu driven real estate catalogue sys...

Implement a menu driven real estate catalogue system that allows users to perform various catalogue maintenance and search tasks.  You are only allowed to use the C programming la

201 it, overloadstream insertion opertator to display the data of object on...

overloadstream insertion opertator to display the data of object on the console

Luminous Jewels - The Polishing Game, Byteland county is very famous for lu...

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Standard input- output using motorola and intel devices, Talking to IO boar...

Talking to IO boards inside a computer or microcontroller depends upon the principles used by the microprocessor to address physical devices. On Motorola systems all devices connec

#, #Write a program to find the area under the curve y = f(x) between x = a...

#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

Keywords in cpp, Define Keywords in C++ K e y w o r d s: ...

Define Keywords in C++ K e y w o r d s: K e y w o rd s a r e t h e w o rd s a l r e a d y u s e d b y C + + i n i t s c

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd