Ask Question
29 December, 04:05

Mix 'em Let s1 and s2 be 2 c-strings of the same length. Write a function char * mixem (char*s1, char * s2) which returns a c-string made up of the characters of s1 and s2 "interleaved", starting with the first character of s1. Example: S1="abc", s2="123" The call mixem (s1, s2) returns the c-string "a1b2c3" Note: If s is a c-string, strlen (s) returns the length of the string (not counting the terminating null character '/0'.) Every c-string has a null character at the end.

+4
Answers (1)
  1. 29 December, 07:30
    0
    See Explaination

    Explanation:

    #include

    #include

    using namespace std;

    char * mixem (char * s1, char * s2);

    int main () {

    cout << mixem ("abc", "123") << endl;

    cout << mixem ("def", "456") << endl;

    return 0;

    }

    char * mixem (char * s1, char * s2) {

    char * result = new char[1 + strlen (s1) + strlen (s2) ];

    char * p1 = s1;

    char * p2 = s2;

    char * p = result;

    while (*p1 || * p2) {

    if (*p1) {

    *p = * p1;

    p1++;

    p++;

    }

    if (*p2) {

    *p = * p2;

    p2++;

    p++;

    }

    }

    *p = '/0';

    return result;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Mix 'em Let s1 and s2 be 2 c-strings of the same length. Write a function char * mixem (char*s1, char * s2) which returns a c-string made ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers