alright..so i have to create an overloaded func where i replace O with E in str and replace world with jack in str and print from main using pointers to pass my strings to the func(needs to adhere to the mentioned)...need help ASAP ppllzz..
thnx

#include <iostream>

using namespace std;

void strrep(char *ptr, char *charactobereplaced);

void strrep(char *ptr, char *wordtobereplaced)

int main()
{
	char str[] = "hello world";

	char wordtobereplaced[] = "world";

	cout<<"The string is "<<str<<" and I will replace o's with e's"<<endl;

	strrep(str, "o");

	cout<<"The modified string is "<<//how can i print from here???<<endl;

	strrep(str, wordtobereplaced)

	cout<<"The modified string is "<<//how can i print from here???<<endl;

	return 0;
}

void strrep(char *ptr, char *charactobereplaced)
{
	while(*ptr == '/0')
	{

		if(*ptr == *charactobereplaced)
		{
			ptr = "e";
		}

		*ptr++;
	}
	
}

void strrep(char *ptr, char *wordtobereplaced)
{
	while(*ptr == '/0')
	{

	
	
	}
}

alright..so i have to create an overloaded func where i replace O with E in str and replace world with jack in str and print from main using pointers to pass my strings to the func(needs to adhere to the mentioned)...need help ASAP ppllzz..
thnx

cuz this is what im supposed to do but i cant really do it..stuck..and so far what ive done doesnt work either

Hi,

First of all both your functions are same. It will give compilation error at the start

void strrep(char *ptr, char *charactobereplaced);

void strrep(char *ptr, char *wordtobereplaced)

Also you can do this with the same function , there is no need to create two functions. Look at the code given below

void strrep(char *ptr, char *wordtobereplaced)
{
  int len= strlen(wordtobereplaced);
 if(len>1)
 { 
   int i=0;
   while(ptr!=NULL)
   { 
      if !(strcmp(ptr,wordtobereplaced))
        *ptr[i]='E';
      i++;*ptr++;
     
}
}
else

{
  if !(strcmp(ptr,wordtobereplaced))
  *ptr[i]="jack";

}


}

Check this code and please revert back in case of any query or error.

This article has been dead for over six months. Start a new discussion instead.