Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago