[C++] Pojawiające się dziwne znaki

Witam, mam oto taki kod:

main.cpp

#include 

#include 

#include "Text.h"


using namespace std;


int main()

{

    for(;;)

    {

        cout << " ***********MENU***************" << endl;

        cout << "(1) Dodaj dwa teksty" << endl;


        int choice;

        cin >> choice;

        switch(choice)

        {

            case 1:


            char * tempFirstText = new char[100];

            char * tempSecondText = new char[100];


            char *firstText;

            char *secondText;




            cout << "Podaj pierwszy tekst" << endl;

            cin.ignore();

            cin.getline(tempFirstText,100);

            cout << "Podaj drugi tekst" << endl;

            cin.ignore();

            cin.getline(tempSecondText,100);


            firstText = new char[strlen(tempFirstText)+1];

            secondText = new char[strlen(tempSecondText)+1];


            for(int i=0;i
            {

                firstText[i] = tempFirstText[i];

            }

            firstText[strlen(tempFirstText)] = '\0';


            for(int i=0;i
            {

                secondText[i] = tempSecondText[i];

            }

            secondText[strlen(tempSecondText)] = '\0';

            Text A(firstText);

            Text B (secondText);


            cout << "Polaczony tekst ma postac: " << (A+B)->GetText() << endl;


        }

    }

    return 0;

}

text.cpp

#include "Text.h"

#include 

#include 


Text:: Text( const char * lString)

{

    text = new char[strlen(lString)];

    for(int i=0;i
    {

        text[i] = lString[i];

    }


}

Text * Text::operator+(const Text& variable)

{

    int totalLength = strlen(this->text)+ variable.GetLength();

    int counter = 0;

    char *allText = new char[totalLength];

    for(int i=0;i
    {

        if(itext))

        {

            allText[i] = this->text[i];

        }

        else

        {

            allText[i] = variable.text[counter];

            counter++;

        }

    }

    Text *newText = new Text(allText);

    return newText;


}

text.h

class Text

{

    public:

    ~Text(){}

    Text(const char *);

    Text * operator+(const Text&);

    private:

    char * text;

}

Program oczywiście jest jeszcze niedokończony.

Problem polega tutaj na tym, że program wyświetla mi dziwne znaki: http://imageshack.us/photo/my-images/60 … znaki.jpg/

Przecież tworzę tablicę, która ma pomieścić tyle znaków ile potrzeba, to skąd nagle biorą się te dodatkowe znaki? Może problem jest banalny, ale dawno nie pisałem nic w C++ więc mam nadzieję, że mi pomożecie :slight_smile:

Ja też dawno nic nie pisałem, ale problem wygląda na taki, że jakby któraś z pętli szła za daleko i zapisuje Ci śmieci z pamięci które jest już za tablicą.

To tak na szybko póki co nie mogę bardziej pomóc bo nawet nie mam przy sobie kompilatora coby pokombinować :slight_smile: