/*4. Consider what happens if you give strdup(), findx(), and 
strcmp() an argument that is not a C-style string. Try it! First 
figure out how to get a char* that doesn’t point to a 
zero-terminated array of characters and then use it (never do this 
in real — non-experimental — code; it can create havoc). Try it 
with free-store-allocated and stack-allocated “fake C-style 
strings.” If the results still look reasonable, turn off debug 
mode. Redesign and re-implement those three functions so that they 
take another argument giving the maximum number of elements 
allowed in argument strings. Then, test that with correct C-style 
strings and “bad” strings.
*/

#include <iostream>
using namespace std;

#define MAXLENGTH 10000

int strcmp(const char* s1, const char* s2) {
	while (*s1 == *s2 && *s1 && *s2) {
		++s1;
		++s2;
	}
	if (!*s1 && !*s2) return 0;
	else if (!*s1 || *s1 < *s2) return 1;
	else return -1;
}

int main() {
	cout << "Enter two strings:\n";
	char* s1 = new char[MAXLENGTH];
	char* s2 = new char[MAXLENGTH];
	cin.getline(s1, MAXLENGTH);
	int i = strlen(s1);
	*(s1 + i) = '^';
	cout << "s1 = " << s1 << " length = " << strlen(s1) << '\n';
	while (cin.getline(s2, MAXLENGTH)) {
		cout << "s2 = " << s2 << " length = " << strlen(s2) << '\n';
		i = strlen(s2);
		*(s2 + i) = '^';
		cout << strcmp(s1, s2) << endl;
		cout << "Enter two strings:\n";
		cin.getline(s1, MAXLENGTH);
		i = strlen(s1);
		*(s1 + i) = '^';
		cout << "s1 = " << s1 << " length = " << strlen(s1) << '\n';
	}

}
