/**
7. Write versions of the cat_dot()s from the previous exercises to take C-style strings as
arguments and return a free-store-allocated C-style string as the result. Do not use standard
library functions or types in the implementation. Test these functions with several strings. Be
sure to free (using delete) all the memory you allocated from free store (using new). Compare
the effort involved in this exercise with the effort involved for exercises 5 and 6.
*/

#include <iostream>
#include <string>
using namespace std;

char* cat_dot(const char* s1, const char* s2)
{
    int n1=0, n2=0;
    while(s1[n1]) ++n1;
    while(s2[n2]) ++n2;
    char* cat = new char[n1+n2+1];
    /*for(int i = 0; i < n1; ++i)
        cat[i]=s1[i];
    cat[n1] = '.';
    for(int i = n1+1; i < n1+n2+1; ++i)
        cat[i]=s2[i-1-n1];
    cat[n1+n2+1]='\0';*/
    while(*s1) {
        *cat=*s1;
        cat++;
        s1++;
    }
    *cat='.';
    cat++;
    do {
        *cat=*s2;
        cat++;
    } while(*(s2++));
    *cat='\0';
    cat -= (n1+n2+2);
    return const_cast<char*>(cat);
}

int main() {
    char* s1 = "catwoeiur";
    char* s2 = "dog";
    cout << cat_dot(s1,s2);
}

