Originally Posted by
FlyingIsFun1217
Not to sound to braindead, but could you show an example of how to do this? If anything, just don't give me a straight example, I wanna figure it out myself
FlyingIsFun1217
Well, if you have a line of input, with spaces [tabs may be separators too, if you like], scan through the line [or use "find" or "locate", whatever it is called] to find the spaces, and copy each portion into a separate string [I suggested char array, but I guess the better solution is to have an array of C++ style strings]. Give each function a number of strings and a pointer to the array of strings. So for example, the function to do "cd" would look like this:
Code:
int cd(int argc, string *argv)
{
if (argc != 1) {
cout << "Incorrect number of parameters for \"" << argv[0] << "\"\n";
return 1;
}
res = chdir(argv[1]);
if (!res) {
cout << "Error, could not change to directory \"" << argv[1] << "\"\n";
}
return res;
}
This is untested code, so you may find that it doesn't work quite right - but it should give you an idea.
Note that argv[0] should be the command itself, so for example "cd foo" should give:
Code:
argv[0] = "cd";
argv[1] = "foo";
argc = 2;
--
Mats