C++ Help with creating a shell.
I am still learning C++ as I go, but I am working on creating a shell like program. It's going to be a simple DOS clone...but interestingly enough, will probably require Windows.
Anyways, I'm going to learn at some point how to retrieve the passwords from a file, but for now, and for my practice purposes, you are asked for a new password everytime you run the EXE. And then the new password is checked against what you used to login with a strcmp() statement.
Now, I'd like to know how I can go about adding commands to this that the user can type in. And then eventually add parameters to these commands.
I know of a couple ways in my head, but they are sluggish. I know that while it sits at the prompt, the user can type in a string, and using gets(), I can check the string using a buttload of if-then statements, or I could use a switch statement. But this will cause performance to be disgusting, as the CPU must check and invalidate every possible command, before it finds the one that works.
So my main idea right now is something like:
Code:
...
..
.
prompt()
{
char cmd[41];
char ch[4];
cout << "C:\\>";
gets(cmd);
if(!strcmp(cmd, "exit"))
{
cout << "Are you sure? (y or n)\n";
gets(ch);
if(!strcmp(ch, "y"))
{
return 0;
}
else
{
prompt();
}
}
if(cmd = "dir")
{
.
..
...
}
so as you can see, the coding would be incredibly foul and sluggish. is there any way to improve upon this? The only improvements I have in mind are
1) use switch instead of if
2) use a 2D array that contains the number of a command, and the command, so when the user enters a command, it checks it against the array to see if it exists, if not then an error message is displayed. if it is, then the command is carried out.
AxessTerminated