command line arguments

This is a discussion on command line arguments within the C Programming forums, part of the General Programming Boards category; hi.. could somebody explain to me about command line arguments? and what does it mean by the following If the ...

  1. #1
    belusha
    Guest

    command line arguments

    hi..

    could somebody explain to me about command line arguments?

    and what does it mean by the following

    If the user does not provide the strings as command line arguments, the program must prompt the user to enter each of the strings, and accept them as keyboard input.


    could somebody give me a sample output? would appreciate it. thank you.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: command line arguments

    Originally posted by belusha
    hi..

    could somebody explain to me about command line arguments?
    [--snip--]
    could somebody give me a sample output? would appreciate it. thank you.
    Search the board. This is a common question. Any C book will cover this.

    Code:
    #include <stdio.h>
    int main ( int argc, char*argv[]  )
    {
        int x;
        for( x = 0; x < argc; x++ )
        {
            printf("%s ", argv[x] );
        }
        printf("\n");
    
        for( x = 0; x < argc; x++ )
            printf("argv[%d] is \'%s\'\n",  x, argv[x] );
    
        return 0;
    }
    Search the board if you need more. Call this from a console window with as many arguments as you like. Example:

    myprog arg1 arg2 arg3 adf asdf 324

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Variable argc is the number of arguments on the command line, the first argument, which is argv[0], is always the name of the program. The following arguments are the parameters passed to that program.

  4. #4
    Registered User newbie_grg's Avatar
    Join Date
    Jul 2002
    Posts
    77

    umm.

    argc is what i take as "argument count " (for simplicity)which holds int value.argc holds the number of arrays. argv is what i take as " argument value" . It is an array .
    it is always char* [argc+1]. "+1" is due to "/0" or NULL .
    as shiro said argv[0] is always the exe's name.and argv[1]..... argv[n-1] holds the value.
    "If knowledge can create problems, it is not through ignorance that we can solve them. "
    -Isaac Asimov(1920-1992)

  5. #5
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >> argv is what i take as " argument value" .
    It's actually argument vector. :-)

    >>the first argument, which is argv[0], is always the name of the program.
    Not always, if the program name isn't available from the host environment then argv[0] is "", or a string with no contents terminated by '\0'.
    *Cela*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 02:17 AM
  2. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 04:27 PM
  3. command line arguments
    By vurentjie in forum C Programming
    Replies: 3
    Last Post: 06-22-2008, 07:46 AM
  4. Replies: 10
    Last Post: 09-27-2005, 01:49 PM
  5. NULL arguments in a shell program
    By gregulator in forum C Programming
    Replies: 4
    Last Post: 04-15-2004, 11:48 AM

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