Command line arguments - C

This is a discussion on Command line arguments - C ; How can I access the command line arguments without using argc, argv? -- comp.lang.c.moderated - moderation address: clcm@plethora.net...

+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16

Command line arguments

  1. Default Command line arguments

    How can I access the command line arguments without using argc, argv?
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net

  2. Default Re: Command line arguments

    On 12 Feb 2004 04:48:59 GMT, aniruddha1981@yahoo.co.in (Aniruddha)
    wrote in comp.lang.c.moderated:

    > How can I access the command line arguments without using argc, argv?


    One thing you can do is define your main function like this:

    int main(int cmd_cnt, char **cmd_str)

    .....then you can access command line arguments by using cmd_cnt and
    cmd_str. The names argc and argv are used by common tradition only.
    Like all function parameters the names are local to the function
    definition and can be anything you like.

    Other than that, there is no way possible in standard C.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c++-faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net

  3. Default Re: Command line arguments

    Jack Klein wrote:
    > ... aniruddha1981@yahoo.co.in (Aniruddha) wrote ...
    >>How can I access the command line arguments without using argc, argv?

    > int main(int cmd_cnt, char **cmd_str)


    Perhaps what he was really trying to do was to access the
    arguments outside the function named "main". There are
    essentially two solutions in that case: (1) pass the
    argc and argv arguments down to the function that needs
    them as function arguments, or (2) define some global
    objects into which main() copies thevalues of argc and
    argv; then any function that wants to examine the command-
    line arguments can access then via those global objects.
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net

  4. Default Re: Command line arguments

    In article <clcm-20040211-0004@plethora.net>, Aniruddha
    <aniruddha1981@yahoo.co.in> writes
    >How can I access the command line arguments without using argc, argv?


    By writing:

    int main(int argument_count, char* arguments[]){
    // etc.
    }

    Or go and hack into your platform's startup code (yes I have actually
    done that many years ago on a pure MSDOS 8086 platform)


    --
    Francis Glassborow ACCU
    Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
    For project ideas and contributions: http://www.spellen.org/youcandoit/projects
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net

  5. Default Re: Command line arguments

    Jack Klein <jackklein@spamcop.net> wrote in message news:<clcm-20040211-0013@plethora.net>...
    > On 12 Feb 2004 04:48:59 GMT, aniruddha1981@yahoo.co.in (Aniruddha)
    > wrote in comp.lang.c.moderated:
    >
    > > How can I access the command line arguments without using argc, argv?

    >
    > One thing you can do is define your main function like this:
    >
    > int main(int cmd_cnt, char **cmd_str)
    >
    > ....then you can access command line arguments by using cmd_cnt and
    > cmd_str. The names argc and argv are used by common tradition only.
    > Like all function parameters the names are local to the function
    > definition and can be anything you like.
    >
    > Other than that, there is no way possible in standard C.
    >
    > --


    In some situations you don't "own" or have access to main.
    In that case, if you need to access argc/argv, main has to
    squirrel them away somewhere -- perhaps in static variables and
    provide accessor functions, perhaps in a global variable you can
    access directly -- so you can get at them later.

    BTW, why do you ask? Are you just curious, or is there some
    particular problem you need to solve?

    -David
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net

  6. Default Re: Command line arguments

    Aniruddha wrote:
    > How can I access the command line arguments without using argc, argv?


    At best, this is implementation dependent.

    The short answer is "you cannot" without a lot of slogging
    where angels fear to tread.

    The real question is "why would you ever want to?"
    --
    Ñ
    "It is impossible to make anything foolproof because fools are so
    ingenious" - A. Bloch
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net

  7. Default Re: Command line arguments

    Jack Klein <jackklein@spamcop.net> wrote in message news:<clcm-20040211-0013@plethora.net>...
    > On 12 Feb 2004 04:48:59 GMT, aniruddha1981@yahoo.co.in (Aniruddha)
    > wrote in comp.lang.c.moderated:
    >
    > > How can I access the command line arguments without using argc, argv?

    >
    > One thing you can do is define your main function like this:
    >
    > int main(int cmd_cnt, char **cmd_str)
    >
    > ....then you can access command line arguments by using cmd_cnt and
    > cmd_str. The names argc and argv are used by common tradition only.
    > Like all function parameters the names are local to the function
    > definition and can be anything you like.
    >


    No, I did not mean accessing with a different name. Imagine the definition of
    main like:
    int main ()
    {
    /* ... */
    }
    How do I access the command line arguments.
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net

  8. Default Re: Command line arguments

    Aniruddha wrote:
    > No, I did not mean accessing with a different name. Imagine the definition of
    > main like:
    > int main ()
    > {
    > /* ... */
    > }
    > How do I access the command line arguments.


    You don't. At least, not without some incredibly system-
    dependent technique, and it might not be possible by any
    method on some systems.

    If you need the command-line arguments, define "main"
    properly.
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net

  9. Default Re: Command line arguments

    In article <clcm-20040214-0003@plethora.net>, Douglas A. Gwyn
    <DAGwyn@null.net> writes
    >Jack Klein wrote:
    >> ... aniruddha1981@yahoo.co.in (Aniruddha) wrote ...
    >>>How can I access the command line arguments without using argc, argv?

    >> int main(int cmd_cnt, char **cmd_str)

    >
    >Perhaps what he was really trying to do was to access the
    >arguments outside the function named "main". There are
    >essentially two solutions in that case: (1) pass the
    >argc and argv arguments down to the function that needs
    >them as function arguments, or (2) define some global
    >objects into which main() copies thevalues of argc and
    >argv; then any function that wants to examine the command-
    >line arguments can access then via those global objects.


    There is a third, low-level, platform specific, solution which is to
    know how the OS supplies the data (i.e. where it stashes the command
    line arguments)

    --
    Francis Glassborow ACCU
    Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
    For project ideas and contributions: http://www.spellen.org/youcandoit/projects
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net

  10. Default Re: Command line arguments

    In article <clcm-20040214-0025@plethora.net>, Aniruddha
    <aniruddha1981@yahoo.co.in> writes
    >No, I did not mean accessing with a different name. Imagine the definition of
    >main like:
    >int main ()
    > {
    > /* ... */
    > }
    >How do I access the command line arguments.


    In general you cannot. Knowing how your OS works can often provide a
    mechanism but why bother when C has already provided you one?


    --
    Francis Glassborow ACCU
    Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
    For project ideas and contributions: http://www.spellen.org/youcandoit/projects
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Command line arguments ???
    By Application Development in forum DOTNET
    Replies: 3
    Last Post: 12-11-2007, 06:38 AM
  2. command line arguments
    By Application Development in forum Fortran
    Replies: 4
    Last Post: 12-07-2007, 07:54 AM
  3. regarding command line arguments
    By Application Development in forum C
    Replies: 22
    Last Post: 05-28-2007, 04:13 PM
  4. command line arguments
    By Application Development in forum DOTNET
    Replies: 1
    Last Post: 04-10-2007, 09:51 AM
  5. Re: Command line arguments
    By Application Development in forum DOTNET
    Replies: 0
    Last Post: 02-01-2007, 06:10 PM