Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function called AddStringsstr1(Str1, Str2) that joins two null terminate

ID: 3809668 • Letter: W

Question

Write a function called AddStringsstr1(Str1, Str2) that joins two null terminated ('C') strings and returns the address of the concatenated string. The caller has two null terminated strings ('C' strings) which are held in individual dynamically allocated memory blocks. The function accepts the addresses of these memory blocks as input parameters. The function is required to create a new memory block that is large enough to hold the concatenated string and returns the address of the new memory block holding the concatenated string.

Explanation / Answer

char* AddString(const char *s1, const char *s2)
{
    char *con_str= malloc(strlen(s1)+strlen(s2)+1);
    strcpy(con_str, s1);
    strcat(con_str, s2);
    return con_str;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote