c++ (well duh) help

This is a discussion on c++ (well duh) help within the C++ Programming forums, part of the General Programming Boards category; when u start up a proper dos progra u can can put /? and /c /d to do different things ...

  1. #1
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    c++ (well duh) help

    when u start up a proper dos progra u can can put
    /? and /c /d to do different things

    Just wondering how u would do this

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    You mean something like this?
    Code:
    int main(int argc, char *argv[])
    {
      for(int i = 1; i < argc; i++)
        if(argv[i][0] == '/')
          printf("argument: %s\n", argv[i]+1);
      return 0;
    }

  3. #3
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    not realy

    i mean like
    C:/>format /b
    or
    C:/>dir /w

  4. #4
    Unregistered
    Guest
    Thats what that piece of code do. Try it!

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    This code will do certain things if you include flags (/b, /w, ...)as parameters when you run the program, ie:
    C:/MyFolder/MyProgram /b /w /n /w
    Code:
    int main(int NrOfArguments, char* ArgumentList[])
    {
       if(NrOfArguments > 1)
       {
          for(int i=1; i<NrOfArguments; i++)
          {
             if(strcmp("/b", ArgumentList[i]) == 0)
             {
                //Do something if the flag /b exists
                ...
             }
             else if(strcmp("/w", ArgumentList[i]) == 0)
             {
                //Do something if the flag /w exists
                ...
             }
          }
       }
    
       //The rest of your program
       ...
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    c++ (well duh) help

    well DUH, how about you write something a bit more descriptive for a subject title then!?

    "command line switches" would have been much better.

    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error ?
    By teeyester in forum C++ Programming
    Replies: 8
    Last Post: 08-23-2003, 04:20 PM
  2. Finally, it's done!
    By dP munky in forum Game Programming
    Replies: 29
    Last Post: 05-19-2003, 09:47 AM
  3. well duh!
    By iain in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 01-23-2002, 10:20 PM
  4. cin.getline in reading files?
    By Brown Drake in forum C++ Programming
    Replies: 11
    Last Post: 12-10-2001, 07:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21