Question
#include // size_t for sizes and indexes ///////////////// WRITE YOUR FUNCTION BELOW THIS LINE /////////////////////// char * replace(char * s, char c1, char c2) {
#include
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
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 sStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started