Question: I need help completing the following C++ program. #include #include #include // Reverse string q in place char* reverse_(char* q) { // fill in code
I need help completing the following C++ program.
#include
// use strstr_ to find the substring t (if any) // then use strncat_ and strcat_ to copy the buffers across // finally: delete[] the temporary buffer char* replace_str_(char* s, char* t, char* u) { // fill in code here } void msg_print(const std::string& msg, const std::string s) { std::cout << msg << s << std::endl; } #define BUF_SIZE 100 void msg_print(const std::string& msg, const std::string s) { std::cout << msg << s << std::endl; } int main() { std::cout << "LAB: (More advanced) C++/C string functions to implement... " << "\tchar* reverse_(char* s) " << "\tchar* reverse_new_(char* s) " << "\tchar* strchr_(char* s, char c) " << "\tchar* strrchr_(char* s, char c) " << "\tchar* strstr_(char* s, const char* t) " << "\tchar* strncat(char* s, const char* t, size_t n) " << "\tchar* replace_(char* s, char c, char d) " << "\tchar* replace_str_(char* s, const char* t, size_t n) ";
char orig[BUF_SIZE] = "indianapolis";
msg_print("before reversing...", orig); reverse_index_(orig); msg_print("and after...", orig); reverse_(orig); msg_print("and after reverse_ptr...", orig);
msg_print(" find p...", strchr_(orig, 'p')); msg_print("find first i...", strchr_(orig, 'i')); msg_print("find last i...", strrchr_(orig, 'i'));
strcpy(orig, "mississippi"); std::cout << " orig is now: " << orig << " ";
char* p = replace_(orig, 'i', 'X'); std::cout << "after replacing i with X, orig is: " << orig << " ";
strcpy(orig, "mississippi"); std::cout << " orig is back to: " << orig << " ";
p = replace_str_(orig, "ss", "KETCHUP"); std::cout << "after replacing 'ss' with 'KETCHUP', orig is now: " << p << " ";
std::cout << " ...done "; return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
