Thread: Passing argument to a program

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    68

    Passing argument to a program

    Hi All,
    Code:
    int main(int argc, char *argv[])
    {
       if (argc >1 )
      {
       //if there is an argument  - take a name from it.
         inifile = argv[1];
       }
       else
       {
          //default name
           inifile = "Settings.ini";
       }
    
     //and so on.....
    The problem is - the program always takes default name.
    Even if i type MyProg.exe test.ini - it takes default file - Settings.ini

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    The code you posted seems ok.
    Can you post the whole code?
    Try to trace the program in debugger.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    68
    Try to trace the program in debugger.
    Thanks, bug found

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing pointer argument
    By timhxf in forum C Programming
    Replies: 8
    Last Post: 01-08-2007, 10:38 AM
  2. passing a function as an argument
    By angelscars in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2005, 09:53 PM
  3. Passing a function as an argument
    By Xzyx987X in forum C Programming
    Replies: 10
    Last Post: 04-20-2004, 10:32 PM
  4. Argument passing
    By Tarper67 in forum C++ Programming
    Replies: 1
    Last Post: 06-13-2003, 02:59 PM
  5. argument passing
    By theweirdo in forum C Programming
    Replies: 1
    Last Post: 01-29-2002, 07:42 PM