Question: #include // size_t for sizes and indexes ///////////////// WRITE YOUR FUNCTION BELOW THIS LINE /////////////////////// const char* myStrNCpy(char* dest, const char* src, int max) {

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

#include // size_t for sizes and indexes ///////////////// WRITE YOUR FUNCTION BELOW THIS LINE /////////////////////// const char* myStrNCpy(char* dest, const char* src, int max) {

while(src[max] != '\0') { dest[max] = src[max]; max++; } dest[max] = src[max]; return dest; }

///////////////// WRITE YOUR FUNCTION ABOVE THIS LINE /////////////////////// // These are OK after the function #include #include using namespace std;

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

void studentTests() { cout

CHECK((char*)"hello", "bob", 9, "hellobob"); CHECK((char*)"abc", "123", 4, "abc"); CHECK((char*)"abc", "123", 6, "abc12");

cout

int main() { studentTests(); } #include void CHECK(char* dest, const char* src, int max, const string& expected) { char data1[1024], data2[1024]; strcpy(data1, dest); strcpy(data2, src); string msg = "myStrNCopy(\"" + string(data1) + "\", \"" + string(data2) + "\", " + to_string(max) + ")"; auto p = myStrNCpy(data1, data2, max); string actual = (p ? string(p) : "nullptr"); if (expected == actual) cout OK" , found "

Hello, this is what I have done, but it seems to be wrong so please offer your own solution so I can see my errors. You can also make your own tests if needed and please done in C++.

9 THE MYSTRNCPY FUNCTION Write the function myStrNCpy(). The function has three parameters: a char*dest, a const char * src, and an int max, which represents the maximum size of the destination buffer. Copy the characters in src to dest, but don't copy more than max-1 characters. Make sure you correctly terminate the copied string. The function returns a pointer to the first character in dest

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!