Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int get_length(const char *ptr)
- {
- for (int idx = 0; ptr[idx] != '\0'; idx++)
- {
- if (ptr[idx + 1] == '\0')
- return idx + 1;
- }
- return -1;
- }
- char *my_strconcat(const char *ptr1, const char *ptr2)
- {
- int len = get_length(ptr1) + get_length(ptr2);
- char *writable = new char[len + 1];
- writable[len] = '\0';
- bool check = false;
- for (int idx = 0; idx < len; idx++)
- {
- if (ptr1[idx] == '\0')
- {
- check = true;
- }
- if (check)
- {
- writable[idx] = ptr2[idx - get_length(ptr1)];
- continue;
- }
- writable[idx] = ptr1[idx];
- }
- return writable;
- }
- char *convert_string(string pString)
- {
- char *writable = new char[pString.size() + 1];
- int le = pString.size();
- writable[le] = '\0';
- for (int idx = 0; idx < le + 1; idx++)
- {
- writable[idx] = pString[idx];
- }
- return writable;
- }
- int main()
- {
- string in1;
- string in2;
- char *out;
- cout << "Bitte ersten Text eingeben (ggfs. mit Leerzeichen): ? ";
- getline(cin, in1);
- cout << "Bitte zweiten Text eingeben (ggfs. mit Leerzeichen): ? ";
- getline(cin, in2);
- if (in1 != "" && in2 != "")
- {
- char *cstr1 = convert_string(in1);
- char *cstr2 = convert_string(in2);
- out = my_strconcat(cstr1, cstr2);
- cout << "Ergebnis my_strconcat(): " << out << endl;
- }
- else
- {
- cout << "Ergebnis my_strconcat(): " << endl;
- }
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment