Menu
support@authoritypapers.com
+1(805) 568 7317

include size t for sizes and indexes write your function below this line 5152043

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 dont 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

#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
    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 << ” + ” + msg + “->OK”
    else
        cout << ” X ” + msg + ” expected<“” + expected + “”>, found <“” + actual + “”>”
}

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&#39;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

"Order a similar paper and get 15% discount on your first order with us
Use the following coupon
"GET15"

Order Now