Hello. I'm writing a ZORK clone, and I am trying to use cin.getline() to obtain the program's inputs from the console. The basic piece of code I'm using for it is as follows:

Code:
    char *str;
    cin.getline(str, MAXCOMMANDLENGTH, '\n');
    string command;
    command.assign(str);
It works fine if it's only done once. When I try to use the same basic code more than once, it sometimes crashes and sometimes doesn't. I've tried using it both once and more than once in the same function, using it in multiple functions, messing with the variable names, both using and not using recursion, etc. Whether I can get it to work just fine on multiple occasions seems to follow no pattern whatsoever. The only thing I have noticed is that if I don't change anything at all about the code, then its reliability is consistent.

An example is as shown:

Code:
string Engine::getInput()
{
    char *str1;
    cin.getline(str1, MAXCOMMANDLENGTH, '\n');
    string command;
    command.assign(str1);
    return command;
}

void Engine::requestResponse()
{
    char *str;
    cin.getline(str, MAXCOMMANDLENGTH, '\n');
    string command;
    command.assign(str);
    interpretAll(command);
}
That works fine. Another example:

Code:
string Engine::getInput()
{
    char *str1;
    cin.getline(str1, MAXCOMMANDLENGTH, '\n');
    string command;
    command.assign(str1);
    return command;
}

void Engine::requestResponse()
{
    getInput(); // change
    getInput(); // change
    char *str;
    cin.getline(str, MAXCOMMANDLENGTH, '\n');
    string command;
    command.assign(str);
    interpretAll(command);
}
That also works fine. But this does not work:

Code:
string Engine::getInput()
{
    char *str1;
    cin.getline(str1, MAXCOMMANDLENGTH, '\n'); // crashes here
    string command;
    command.assign(str1);
    return command;
}

void Engine::requestResponse()
{
    char *str;
    cin.getline(str, MAXCOMMANDLENGTH, '\n');
    getInput(); // change
    string command;
    command.assign(str);
    interpretAll(command);
}
I have reason to suspect it has something to do with a segmentation fault. I have tried many different combinations of things (some of them being in the body of that interpretAll() function), but I have found no pattern. Does anybody know what's going on? Thanks!