Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8463143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:23:07+00:00 2026-06-10T14:23:07+00:00

So my assignment is: Using the strncpy and strncat functions in #include<cstring> , implement

  • 0

So my assignment is:

Using the strncpy and strncat functions in #include<cstring>,
implement a function

void concat(const char a[ ], const char b[ ], char result[ ],
                 int result_maxlength)

that concatenates the strings a and b to the buffer result. Be sure
not to overrun the result. It can hold result_maxlength characters,
not counting the \0 terminator. (That is, the buffer has
buffer_maxlength + 1 bytes available.) Be sure to provide a ‘\0’
terminator.

My solution (thus far) is below but I don’t know what I’m doing wrong. Not only do I get a run-time check failure 2 error when I actually run the program, but I’m unsure where I should be adding the \0 terminator or even if I should be using strncat rather than strncpy. Hopefully someone can lead me in the right direction. And yes this is hw. That’s why I said just lead me in the right direction so that I can try to figure it out :p

#include <iostream>
#include <cstring>
using namespace std;

void concat(const char a[ ], const char b[ ], char result[ ], int result_maxlength);

int main()
{
    char a[] = "Woozle";
    char b[] = "Heffalump";
    char c[5];
    char d[10];
    char e[20];

    concat(a, b, c, 5);
    concat(a, b, d, 10);
    concat(a, b, e, 20);
    cout << c << "\n";
    cout << d << "\n";
    cout << e << "\n";

    return 0;
}

void concat(const char a[ ], const char b[ ], char result[ ], int result_maxlength)
{    
    strncat(result, a, result_maxlength);
    strncat(result, b, result_maxlength);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:23:08+00:00Added an answer on June 10, 2026 at 2:23 pm
    1. strncpy from a to result (whatever is smaller, lenght of a or result_maxlength)
    2. strncat from b to remaining of result (whatever is smaller, lenght of b or result_maxlength- lenght of a)

    3. before every return just put a \0 at last position result[result_maxlength-1] ='\0';

    It’s actually not specified WHAT to do if result is too short, should you add trailing 0 or not. I guess you’d better terminate that string.

    tip : remaining of result is result+strlen(a)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing the calloc function in a memory management assignment (I am using
The assignment operator can be overloaded using a member function but not a non-member
I have an assignment where I need to implement church numerals in SML using
When attemptiing to solve the below assignment : Using the Arithmetic operators ( +,-,*,/)
Currently I'm working on an assignment and using C++ for the first time. I'm
When you update DataGridView.DataSource using the assignment operator, the DataSourceChanged event handler is called.
Are there any advantages or disadvantages to using multiple assignment in a statement? In
I've noticed some inconsistent (inconsistent to me) behaviour in data.table when using different assignment
How to set entire HTML in MSHTML? I am trying using this assignment: (Document
I'm using this code for my web assignment: http://csstechniques.blogspot.sg/2007/05/super-simple-css-bars.html But how do I show

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.