/*
4. 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.
*/

#include <iostream>
using namespace std;

#define MAXLENGTH 10000

char* strdup01(const char* cstr) {
	char* cstrCopy = new char[MAXLENGTH];
	int i{ 0 };
	while (*cstr) {
		cstrCopy[i++] = *cstr++;
	}
	cstrCopy[i] = '\0';
	return cstrCopy;
}

int main() {
	cout << "Enter a string";
	char* cstr = new char[MAXLENGTH];
	char* cstrCopy = new char[MAXLENGTH];
	while (cin.getline(cstr, MAXLENGTH)) {
		cstrCopy = strdup01(cstr);
		cout << cstrCopy;
		cout << "Enter a string";
	}
	delete[] cstr;
	delete[] cstrCopy;
}