Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 10 / Examples / MyString
diff options
context:
space:
mode:
1 files changed, 13 insertions, 4 deletions
-rw-r--r--Sem. 10/Examples/MyString/MyString.cpp17
diff --git a/Sem. 10/Examples/MyString/MyString.cpp b/Sem. 10/Examples/MyString/MyString.cpp
index ffa8bb1..8d282d2 100644
--- a/Sem. 10/Examples/MyString/MyString.cpp
+++ b/Sem. 10/Examples/MyString/MyString.cpp
@@ -13,11 +13,20 @@ void MyString::free()
delete[] str;
}
-MyString::MyString()
+MyString::MyString(const char* data)
{
- str = new char[1];
- str[0] = '\0';
- size = 0;
+ if(data == nullptr)
+ {
+ str = new char[1];
+ str[0] = '\0';
+ size = 0;
+ }
+ else
+ {
+ size = strlen(data);
+ str = new char[size + 1];
+ strcpy(str, data);
+ }
}
size_t getNumSize(size_t num)