I'm working on a shell project in c++. All the functionality I need is there. There is one problem, however. My exit condition is when the user inputs "exit", which works fine unless the previous command is a random string (ex: asldjkf). When a random string is entered and then exit is entered at the next prompt, it loops once more and then exits upon user entering "exit" again.
I've just been debugging using cout and I know the conditions to exit are met. Can someone tell me what might be happening here?`
here is what i'm calling in main()
UNIX_shell myShell;
char * args[100];
string check = "";
argsIndex = 0;
string userIn;
while(myShell.exitstatus == false)
{
std::cin.getline(myShell.userIn, 256);
check = string(myShell.userIn);
cout << check << endl;
myShell.getArgs(check, args);
if(myShell.exitstatus == false && string(myShell.userIn) != "exit")
cout << myShell.userName + "@" + myShell.hostName + ":~" + getcwd(NULL, 0) + "/";
}
return 0;
and here is where the exit condition is being met immediately after calling getArgs():
void UNIX_shell::getArgs(string check, char * args[])
{
cout << "check is" << check << endl;
if(check[0] == 'e' && check[1] == 'x' && check[2] == 'i' && check[3] == 't')
{
cout << "shadoom" << endl;
this->exitstatus = true;
cout << "exit = "<< exitstatus << endl;
return;
}
...
So if I run my program and enter something like ls, or ps -aef, and then type exit, everything runs fine, and the program exits.
But if i run my program, enter "shit" in the command line, then enter "exit" at the next prompt, i get a second prompt, then when i type exit again, it exits. I've been trying to debug this for over an hour. Thanks for any help in advance.