/* Write a function, char* strdup(const char*), that copies a C-style string into memory it
allocates on the free store. Do not use any standard library functions. Do not use subscripting;
use the dereference operator * instead. */


#include <iostream>

char* strdup(const char* s) {

    int size{0};
    for (;*s++; size++);
    char* str_ptr = new char[size + 1];
    char* str = {nullptr};

    s -= size;

    for (;*s++; *str_ptr++ = *s);
    str_ptr -= size;

    str = str_ptr;
    delete[] str_ptr;
    return str;
}

int main()
{
    char* rdy = {strdup("HELLO")};
    std::cout << rdy << std::endl;
}