Question: #include // size_t for sizes and indexes ///////////////// WRITE YOUR FUNCTION BELOW THIS LINE /////////////////////// char * replace(char * s, char c1, char c2) {

 #include // size_t for sizes and indexes ///////////////// WRITE YOUR FUNCTION

#include // size_t for sizes and indexes ///////////////// WRITE YOUR FUNCTION BELOW THIS LINE /////////////////////// char * replace(char * s, char c1, char c2) { auto p = s; while(*p) { if(*p == c1) { *p = c2; } p++; } return p; } ///////////////// WRITE YOUR FUNCTION ABOVE THIS LINE /////////////////////// // These are OK after the function #include #include using namespace std;

void CHECK(char*, char, char, const string&);

void studentTests() {

cout

{ char s[] = "Acrdvcrk"; CHECK(s, 'c', 'a', "Aardvark"); } { char s[] = "hallo thara world!"; CHECK(s, 'a', 'e', "hello there world!"); } { char s[] = "ibricidbri"; CHECK(s, 'i', 'a', "abracadbra"); } { char s[] = "somelhing amazing"; CHECK(s, 'l', 't', "something amazing"); } // need error check if found no letters to replace { char s[] = "no letters to switch"; CHECK(s, 'u', 't', s); }

cout

int main() { studentTests(); } #include void CHECK(char * s, char c1, char c2, const string& expected) { string msg = "replace(\"" + string(s) + "\")" ;

auto p = replace(s, c1, c2);

string actual = (p ? string(p) : "nullptr"); if (expected == actual) cout OK" " , found "

Hello, need help with my function. It seems to be just wrong and I need help with a solution done in C++. Thank you for any help offered.

11THE REPLACE PROBLEM Write the function replace). The function has three parameters: a char* s, a char c1 and a char c2. Replace all instances of c1 with c2. Return a pointer to the first character in s

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!