//
// Created by user on 18. 4. 12.
//
#ifndef XPP_MOCK_H
#define XPP_MOCK_H
#endif //XPP_MOCK_H
int sizeOfStr(char str[]);
class MyString {
private:
char memory[80];
public:
MyString(char str[] = "") {
for (int i = 0; i < str[i] != '\0' && i < 80; ++i) {
memory[i] = str[i];
}
}
int size() {
return sizeOfStr(memory);
}
void cpy(char str[]) {
int i;
for (i = 0; str[i] != '\0' && i < 80; ++i) {
memory[i] = str[i];
}
memory[i] = '\0';
}
void cat(char str[]) {
int length = size();
for (int i = 0; str[i] != '\0' && length < 80; ++i) {
memory[length++] = str[i];
}
memory[length] = '\0';
}
int cmp(char str[]) {
int i;
for (i = 0; i < size(); ++i) {
if (str[i] != memory[i]) {
return memory[i] - str[i] > 0 ? 1 : -1;
}
}
return str[i] != '\0' ? -1 : 0;//str 의 크기가 memory의 크기보다 크면 -1을 반환
}
std::string tostring(){
return memory;
}
};
int sizeOfStr(char str[]) {
int counter = 0;
char *m = str;
while (*(m++) != '\0') {
counter++;
}
return counter;
}
#include <iostream>
#include "mock.h"
using namespace std;
int main() {
MyString s1("abcde"); //abcde
cout<<s1.tostring()<<'\n'; //abcde 출력
cout<<s1.size()<<'\n'; //5 출력
s1.cat("fg");//abcdefg
cout<<s1.tostring()<<'\n';//abcdefg 출력
cout<<s1.size()<<'\n';// 7출력
cout<<s1.cmp("abced")<<'\n';// -1 출력
s1.cpy("hello there");
cout<<s1.tostring()<<'\n';// hello there 출력
return 0;
}