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 210673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:01:35+00:00 2026-05-11T18:01:35+00:00

I was interviewed recently and asked to write mystrcat(*s1, *s2, *s3) where s1 and

  • 0

I was interviewed recently and asked to write mystrcat(*s1, *s2, *s3) where s1 and s2 are source string and the concatenated results are given by s3. I was told, don’t worry about memory allocation of s3 and assume s1 and s2 are not null / invalid strings. So I wrote the following lame (crude) program. I was told there is something wrong with s3 or something can go wrong with s3. Could you please tell what it is/ could that be?

void mystrcat(char *s1, char *s2, char *s3)
{
    if (! (s1 || s2 || s3)) return; // one/more pointers are invalid

    // copy string s1 into s3
    while(*s1) {
      *s3 = *s1;
      s1++;
      s3++;
    }

    // concatenate string s2 into s3
    while(*s2) {
      *s3 = *s2;
      s2++;
      s3++;
    }

    *s3 = '\0';
}

Could you please tell me what is wrong here? What would be more professional way of doing it?

  • 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-05-11T18:01:35+00:00Added an answer on May 11, 2026 at 6:01 pm

    Here would be my comments

    • Both s1 and s2 should be typed to const char* since you have no intention of modifying them.
    • You did not verify s3 had enough allocated space to contain s1 and s2’s combined length
    • You are failing silently when the user passed in bad data (NULL values). This is not good because there is no way for a caller to differentiate between a successful and a failing call
    • Your method of verifying s1,s2 and s3 are not null is incorrect (Igor has it right)

    Questions I would have liked you to ask or self answered during the interview

    • How should I express failure to copy the string?
    • Do you want an exact clone of strcat or one that is more modern and does better argument validation?
    • Can I use other standard str functions to complete the answer?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently interviewed with a company and they asked me to write an algorithm
Recently an interviewer asked me about the types of buffers. What types of buffers
An interviewer recently asked me this question: given three boolean variables, a, b, and
I had an interview recently and he asked me about Singleton Design Patterns about
I was recently asked in an interview about the parameter for a copy constructor.
Recently in a technical interview, I was asked to write a program to find
I was recently asked a question, apparently in an Interview, about extending the java.lang.RuntimeException.
All, I was recently asked in one of the technical interviews to write a
Recently I had an interview and I was asked to write a algorithm to
I was recently asked some questions in an interview about Android. I searched for

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.