Thread: command line parameters problem...

  1. #1
    Registered User
    Join Date
    May 2006

    command line parameters problem...

    Hi, I am trying to get this program to take some command line arguements like -l for logging. The problem is my program does not seem to think argv[4] == "-l". Here is my arg check:

    /*Check args*/
        if(argc < 4 || argc == 5 || argc > 6 || (argc == 6 && argv[4] != "-l")){
                cerr << "Incorrect set of parameters(" << argc <<") Usage: sqltest new_file.txt [-load|old_file.txt] database.db [-l log.txt]\n";
    and here is my input:
    sqltest NEW.txt -load new.db -l logfile.txt
    I removed this from my if statement:
     (argc == 6 && argv[4] != "-l")
    and it worked so I am pretty sure I am missing something about comparing command line args to const char*. The same thing is happening when I check argv[2] for "-load" as well.

  2. #2
    Join Date
    Feb 2002
    You're looking for strcmp.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Registered User
    Join Date
    Jan 2005
    Or if you use the C++ string class:
    std::string(argv[4]) != "-l"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. problem in calling DLL
    By bhagwat_maimt in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2006, 10:43 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM