accessing args via command line

Discussion in 'C++' started by mark, Jun 14, 2004.

  1. mark

    mark Guest

    int main(int argc, char *argv[])

    Not giving the argument via command line and trying to access it
    inside the
    program, gives the following error

    on VC++ Application error (launches debugger if requested)
    on Linux g++ "PWD=/home/local" (the present working directory where
    the
    program was called from

    on VC++ it is fine as one is trying to access a memory location which
    has not been defined.
    How is g++ handling this error ? is it ok ?
     
    mark, Jun 14, 2004
    #1
    1. Advertisements

  2. mark

    Pete C. Guest

    mark wrote:
    > int main(int argc, char *argv[])
    >
    > Not giving the argument via command line and trying to access it
    > inside the
    > program, gives the following error
    >
    > on VC++ Application error (launches debugger if requested)
    > on Linux g++ "PWD=/home/local" (the present working directory where
    > the
    > program was called from
    >
    > on VC++ it is fine as one is trying to access a memory location which
    > has not been defined.
    > How is g++ handling this error ? is it ok ?


    Just only access arguments from 0 to argc - 1:

    #include <iostream>
    int main(int argc, char* argv[])
    {
    for(int i = 0; i < argc; ++i)
    std::cout << argv << std::endl;
    return 0;
    }

    - Pete
     
    Pete C., Jun 14, 2004
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arthur J. O'Dwyer

    Re: weird command line args problem with C

    Arthur J. O'Dwyer, Sep 13, 2003, in forum: C Programming
    Replies:
    2
    Views:
    416
    Edd Dawson
    Sep 13, 2003
  2. Edd Dawson

    Strange command line args problem

    Edd Dawson, Sep 13, 2003, in forum: C Programming
    Replies:
    6
    Views:
    438
    Edd Dawson
    Sep 14, 2003
  3. Michael

    command-line args

    Michael, Apr 24, 2004, in forum: Python
    Replies:
    3
    Views:
    560
    Tim Daneliuk
    Apr 25, 2004
  4. Peter Hansen

    RE: command-line args

    Peter Hansen, Apr 24, 2004, in forum: Python
    Replies:
    2
    Views:
    461
    Peter Hansen
    Apr 25, 2004
  5. Edward WIJAYA
    Replies:
    1
    Views:
    468
    Sam Holden
    Oct 28, 2004
  6. command line args

    , Mar 14, 2005, in forum: Python
    Replies:
    2
    Views:
    414
    Steven Bethard
    Mar 14, 2005
  7. k8
    Replies:
    7
    Views:
    341
    Tim Roberts
    Oct 9, 2005
  8. vjonweb

    Wierd problem with command line args

    vjonweb, Jul 29, 2006, in forum: C Programming
    Replies:
    5
    Views:
    393
    Dik T. Winter
    Jul 30, 2006
Loading...