Thread: Command Prompt Shell

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> Still doesn't explain my current error though, which is what I'm most interested in at the moment...
    Did fixing the substr call help?

    >> tempdirectory.erase(0,tempdirectory.length());
    BTW, this line does nothing important. The variable is about to go out of scope anyway, and if you wanted to clear a string you should use clear().
    Last edited by Daved; 09-18-2007 at 03:51 PM.

  2. #17
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Quote Originally Posted by matsp View Post
    You may also want to take your input string and split it at spaces into a int argc, char *argv[] set. That way, you can easily sort out things like "rmdir /s directory-to-delete"
    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

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by FlyingIsFun1217 View Post
    Still doesn't explain my current error though, which is what I'm most interested in at the moment...

    Good tips though, I will definitely split it up into separate functions soon

    FlyingIsFun1217
    Yes, that's true, and I didn't try to say anything about that, because as far as I was concerned, CornedBee seemed to have already answered that.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #19
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by FlyingIsFun1217 View Post
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #20
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Don't forget that argv[argc] must be valid and a null pointer.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #21
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Since I've only been coding in C++ for a year, in between school assignments, I haven't had great practice at it, and in this case, I believe arrays are what I really need to know better.

    I'll look it up, and as usual, thanks for the awesome help!
    FlyingIsFun1217

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 34
    Last Post: 05-27-2009, 12:26 PM
  2. What shell is more powerful?
    By xddxogm3 in forum Tech Board
    Replies: 10
    Last Post: 07-24-2004, 10:47 PM
  3. System.ini Shell Problems
    By (TNT) in forum Windows Programming
    Replies: 2
    Last Post: 08-26-2001, 01:05 PM